tests/testthat/test-postTransaction.R

context("Test the post transaction (simple)")

body = "AAAAABYNKU6c4ROssxuqKACreDTSHszRk+6QjoN/5j7/aCdPAAA4pACk9+IAAAADAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAABAAAADHlvdXJNdW1zQXJzZQAAAAEAAAAAAAAAAQAAAACdpD9sS2jlS4+g0cF9ZjMgNJrm2J2L7tIPDnaA6sV7hQAAAAAAAAAATXxtAAAAAAAAAAAB/2gnTwAAAEAkjv4/L4hSS2HMzEk0u+sXATKfQVjZr3ja1KZoQd22Ivf1hXTHERS5hF86wEhiCxPL5i0HQBpkrnZMynoDshwP"

test_that("Transaction details are returned.", {
  txn = postTransaction(body, domain = domain)
  expect_named(txn, c("_links", "hash", "ledger", "envelope_xdr", "result_xdr", "result_meta_xdr"))
  expect_equal(txn$ledger, 10847297)
  expect_equal(txn$envelope_xdr, body)

  post_link = sprintf("https://horizon-testnet.stellar.org/transactions/%s", txn$hash)
  expect_equal(as.character(txn[['_links']]), post_link)
})

test_that("Changing the body returns an invalid XDR response.", {
  bad_body = paste0(body, "AA")
  response = postTransaction(bad_body, domain = domain)

  expect_named(response, c("type", "title", "status", "detail", "extras"))
  expect_equal(response$status, 400)
  expect_true(grepl("^Horizon could not decode the transaction envelope in this request\\.",
                    response$detail))
})
froocpu/xlm documentation built on May 13, 2019, 4:02 a.m.