Files
simplex-chat/tests/Bots/StoreService/NamesSenderTests.hs
T
ad75fe706f store: sell and register SimpleX names (#7979)
* core: add prepaid name codes and length bounds

* store: run the names migration after badges

* store: issue and revoke prepaid name codes

* store: document issuing prepaid name codes

* store: move the ABI helpers to Names.Abi

* store: read the [names] and [chain] settings

* store: add the names chain client and reads

* store: refuse group name codes while names are off

* store: search names and preview links

* store: serve each site on its own port

* scripts: deploy the badges and names sites

* store: document search and the two sites

* store: add the drop_taken_codes migration

* store: read the names codes_only setting

* store: add the names store and order signatures

* store: take name orders by card, crypto or code

* store: document name orders and codes-only

* store: add the names transaction sender

* store: commit and register queued orders

* store: reveal and retry an owner's order

* store: document the gas key

* store: add the name balance migrations

* store: read crypto units, rates and confirmations

* store: keep a taken order's money as a balance

* store: spend a balance on another name

* store: record refunds with //refund

* store: document balances and refunds

* store: add the agreed terms migration

* store: read the terms and community names

* store: answer community and terms in search

* store: sign and store the agreed terms

* store: document the terms and community names

* store: add the invoiced units migration

* store: read the crypto an invoice asks

* store: credit late and overpaid crypto by share

* store: document crediting late crypto by share

* store: add the record changes migration

* store: find an owner's orders and move one

* store: relay owners' link edits on chain

* store: document link edits

* store: move isLoopbackHost to Config

* store: trust dev issuer keys on the local chain

* scripts: build the names site from a submodule

* scripts: add the dev setup and contract run

* store: document the dev setup and names image

* store: send a Stripe idempotency key for names

* tests: wait until a relay lets go of its edit

* store: refuse a link edit deadline under 10 min

* store: count reverted link edits in the year limit

* store: require https for a remote chain node

* store: refuse zero chain confirmations

* store: set up the dev stack from the names branch

* store: rerun a failed unpaid cleanup next pass

* store: never replace a succeeded Stripe intent

* store: refuse an ini setting written as key: value

* store: note the webapp submodule's pinned branch

* store: document confirmLanded judging by ownerOf

* store: update the names webapp submodule

* store-service: register names under the name policy, every name accepting its terms on chain (#7889)

* store: accept each name's terms on chain under the name policy

* ci: run the reduced build on sh/names-deploy

* store: address review: policy re-read, terms reads and startup log

* store: never credit an unconfirmed extra

* store: alert money sent to a paid name invoice

* store: refuse to start on another chain's node

* store: keep orders while the allowance is used up

* store: replace a stalled transaction after 3 blocks

* store: judge a name taken at confirmation depth

* store: bind the template's listener to loopback

* store: scan only the ids of active name orders

* store: refuse unknown [names] and [chain] settings

* store: fetch the webapp submodule in upgrade steps

* store: delete definitions only tests use

* store: lock only name invoices at settlement

* store: retry an unexpired commitment as usual

* store: share the helpers defined twice

* store: test route limits on the running service

* store: fix tests that could not fail

* ci: test the store service on Postgres

* store: count IPv6 clients by their /64

* store: sweep invoices read alone past a list cap

* store: cap checkouts of all clients together

* store: cap the long polls held at once

* store: stop the old badge project at upgrade

* store: keep search lookups free of previews

* store: read the ini as UTF-8 in any locale

* ci: run Postgres store tests in a UTF-8 locale

* store: cap the transactions one order sends

* store: cancel a card intent after three declines

* store: refuse a name price under a cent

* store: send each transaction with gas headroom

* store: cap searches and read terms once per block

* store: never log the group join link

* store: mask the database password at startup

* store: run one instance per database

* store: limit name codes to admins, 100 a day

* store: refuse HighSpeed settlement with names

* store: no unverified receipts with a trusted key

* store: cap the log lines of refused webhooks

* store: check Apple certificates at the signed date

* store: refuse a malformed Stripe publishable key

* store: check the owner before a refund

* store: fold the names migrations into one

* store: read onion name links through the proxy

* store: refund money after paid once confirmed

* store: limit the allowance wait to a dry run

* store: bind loopback when upgrading

* ci: cache and widen the store Postgres job

* store: fix stale and duplicate names tests

* store: fix the submodule path in the upgrade

* store: refuse unpaid name codes on the CLI

* store: apply the review's names test list

* store: finish the review's names test list

* store: restore the base registration tests

* store: pass link hosts that do not resolve here

* store: refuse a move once its sends are used up

* store: take the shared checkout at the provider

* store: hold a search slot for chain reads only

* store: state which refunds are safe on a reference

* store: check a failed order's name before refusing its move (#8060)

* store: test and document the shared checkout cap for name orders

* store: check a failed order's name on chain before refusing its move

* store: test name links whose host lookup fails

* store: test that a search holds its slot through the chain reads only

* store: restore the signed transaction check in the chain tests

* store: remove the chain tests' copy of the signed transaction check

* store: correct the search slot texts and the README's balance endpoints

* docs: system and sequence diagrams of the names service (#8068)

---------

Co-authored-by: sh-agents <350651734+sh-agents@users.noreply.github.com>
Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
Co-authored-by: brenzi-agent <brenzi-agent@brenzi.ch>
Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com>
2026-11-07 10:45:19 +00:00

360 lines
18 KiB
Haskell

{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
module Bots.StoreService.NamesSenderTests (namesSenderTests) where
import Bots.StoreService.FakeEthNode
import Bots.StoreService.NamesStoreTests (issue, order, ownerA, placeCode, t0, usable)
import Bots.StoreService.WebTests (capturingStderr, digestFixture, withServiceStore)
import Control.Concurrent.Async (concurrently)
import Control.Concurrent.STM
import Control.Monad (forM_, replicateM_)
import Crypto.Random (ChaChaDRG)
import Data.ByteArray.Encoding (Base (Base16), convertFromBase)
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import Data.List (sort)
import Data.String (fromString)
import qualified Data.Text as T
import Data.Time.Clock (NominalDiffTime, UTCTime, addUTCTime)
import Data.Word (Word64, Word8)
import Simplex.Messaging.Agent.Store.Common (DBStore, withTransaction)
import qualified Simplex.Messaging.Agent.Store.DB as DB
import qualified Simplex.Messaging.Crypto as C
import StoreService.Config (ChainConfig (..))
import StoreService.Names.Chain
import StoreService.Names.Phases (RegistrationId (..))
import StoreService.Names.Registration (commitCalldata)
import StoreService.Names.Revert (RevertName (..))
import StoreService.Names.Sender
import StoreService.Names.Store (NameTransaction (..), TxFor (..), TxStatus (..), pendingTransactions, registrationTransactions)
import System.Timeout (timeout)
import Test.Hspec
namesSenderTests :: Spec
namesSenderTests = describe "StoreService names: sender" $ do
g <- runIO C.newRandom
it "reads a signed transaction's request back from its raw bytes" $ testDecodeSignedTx g
it "gives concurrent transactions their own nonces, each saved before it is sent" $ testConcurrentNonces g
it "saves nothing and takes no nonce when the dry run reverts or the chain does not answer" $ testNothingSaved g
it "refuses a second transaction for work with one in flight" $ testOneInFlight g
it "settles a receipt only once it is confirmations deep, with its status" $ testConfirmationDepth g
it "keeps a transaction whose send failed, and sends it in the next round" $ testFailedSend g
it "replaces a stuck transaction once the market's fees pass its own, and settles it under the new hash" $ testFeeBump g
it "rebroadcasts a saved raw transaction after a restart while the node does not know it" $ testRestartRebroadcast g
it "hands a dropped transaction whose nonce was used, or a mined one whose receipt was pruned, to its owner, who may send again at the next nonce" $ testDroppedNonceUsed g
it "logs a round that fails on the store, and settles the transaction in the next round" $ testFailedRound g
it "logs a send the node keeps refusing once per error, an underfunded key as an error, in anvil's capitalized form too" $ testRefusedSendLogged g
it "refuses a transaction whose block needs more than the fee cap, saving nothing, and signs at most the cap" $ testFeeCapSubmit g
it "clamps a replacement at the fee cap, and keeps rebroadcasting once a replacement would pass it" $ testFeeCapReplace g
data Setup = Setup
{ node :: FakeEthNode,
store :: DBStore,
clock :: TVar UTCTime,
chain :: ChainClient,
random :: TVar ChaChaDRG
}
withSetup :: TVar ChaChaDRG -> (Setup -> IO a) -> IO a
withSetup = withCapSetup fakeMaxFeePerGas
-- | Two code orders, r1 and r2, two confirmations, and this max fee per gas.
withCapSetup :: Word64 -> TVar ChaChaDRG -> (Setup -> IO a) -> IO a
withCapSetup cap random action = withFakeEthNode $ \node -> withServiceStore $ \store -> do
forM_ [(1, "r1", "alicebakery"), (2, "r2", "bobbakery")] $ \(n, rid, label) -> do
code <- issue store n usable
placeCode store rid ownerA (order label n) code `shouldReturn` Right ()
clock <- newTVarIO t0
chain <- newChainClient random (fakeChainConfig node) {cConfirmations = 2, cMaxFeePerGas = cap}
action Setup {node, store, clock, chain, random}
start :: Setup -> IO Sender
start Setup {random, chain, store, clock} = newSender random chain store (readTVarIO clock)
passTime :: Setup -> NominalDiffTime -> IO ()
passTime Setup {clock} t = atomically $ modifyTVar' clock (addUTCTime t)
testDecodeSignedTx :: TVar ChaChaDRG -> IO ()
testDecodeSignedTx g = withFakeEthNode $ \node -> do
c <- newChainClient g $ fakeChainConfig node
-- calldata over 55 bytes takes a long RLP length
let request = TxRequest {trTo = fakeSponsor, trData = B.replicate 300 0xab, trNonce = 70000, trGasLimit = 450000, trMaxFeePerGas = 31000000000, trMaxPriorityFeePerGas = 0}
Right SignedTx {stRaw} <- signTransaction g c request
decodeSignedTx stRaw `shouldBe` Right request
decodeSignedTx (B.cons 0x01 $ B.drop 1 stRaw) `shouldBe` Left "transaction: not an EIP-1559 transaction"
decodeSignedTx (B.take 100 stRaw) `shouldBe` Left "RLP: truncated"
testConcurrentNonces :: TVar ChaChaDRG -> IO ()
testConcurrentNonces g = withSetup g $ \s@Setup {node, store} -> do
sender <- start s
-- both dry runs pass before either reads the registrar's nonce
setFault node "eth_getTransactionCount" $ Slow 300000
(Right a, Right b) <- concurrently (submitTransaction sender (TxCommit r1) fakeController $ commit 1) (submitTransaction sender (TxCommit r2) fakeController $ commit 2)
clearFault node "eth_getTransactionCount"
sort [ptNonce a, ptNonce b] `shouldBe` [0, 1]
saved <- withTransaction store pendingTransactions
map (\NameTransaction {ntFor, ntNonce, ntHash} -> (ntFor, ntNonce, ntHash)) saved
`shouldMatchList` [(TxCommit r1, ptNonce a, ptHash a), (TxCommit r2, ptNonce b, ptHash b)]
sentTransactions node `shouldReturn` map ntRaw saved
mapM_ (mineHash node) [ptHash a, ptHash b]
_ <- mine node []
followTransactions sender
forM_ [a, b] $ \p -> outcomeOf p >>= (`shouldSatisfy` confirmedAs (ptHash p))
Right c <- submitTransaction sender (TxRegister r1) fakeSponsor $ commit 3
ptNonce c `shouldBe` 2
testNothingSaved :: TVar ChaChaDRG -> IO ()
testNothingSaved g = withSetup g $ \s@Setup {node, store} -> do
sender <- start s
setFault node "eth_estimateGas" $ revertFault insufficientAllowance
submitTransaction sender (TxCommit r1) fakeController (commit 1) `refusedWith` SEChain (ChainReverted $ Just RNInsufficientAllowance)
clearFault node "eth_estimateGas"
setFault node "eth_maxPriorityFeePerGas" HttpFailure
submitTransaction sender (TxCommit r1) fakeController (commit 1) `refusedWith` SEChain (ChainUnavailable "eth_maxPriorityFeePerGas: HTTP 502")
clearFault node "eth_maxPriorityFeePerGas"
withTransaction store pendingTransactions `shouldReturn` []
sentTransactions node `shouldReturn` []
Right p <- submitTransaction sender (TxCommit r1) fakeController (commit 1)
ptNonce p `shouldBe` 0
testOneInFlight :: TVar ChaChaDRG -> IO ()
testOneInFlight g = withSetup g $ \s@Setup {node} -> do
sender <- start s
Right p <- submitTransaction sender (TxCommit r1) fakeController (commit 1)
submitTransaction sender (TxCommit r1) fakeController (commit 1) `refusedWith` SEInFlight
Right other <- submitTransaction sender (TxRegister r1) fakeSponsor (commit 2)
ptNonce other `shouldBe` 1
(fmap ptHash <$> inFlightTransaction sender (TxCommit r1)) `shouldReturn` Just (ptHash p)
length <$> sentTransactions node `shouldReturn` 2
testConfirmationDepth :: TVar ChaChaDRG -> IO ()
testConfirmationDepth g = withSetup g $ \s@Setup {node, store} -> do
sender <- start s
Right p <- submitTransaction sender (TxCommit r1) fakeController (commit 1)
-- a wait for an outcome not reached yet ends at its bound
timeout 5000000 (awaitOutcome 300000 p) `shouldReturn` Just Nothing
let TxHash h = ptHash p
block <- mine node [(h, False)]
followTransactions sender
settled sender (TxCommit r1) `shouldReturn` False
_ <- mine node []
followTransactions sender
outcomeOf p `shouldReturn` TOConfirmed (ptHash p) Receipt {receiptSuccess = False, receiptBlock = block}
settled sender (TxCommit r1) `shouldReturn` True
statuses store r1 `shouldReturn` [(ptHash p, TSReverted, Just block)]
testFailedSend :: TVar ChaChaDRG -> IO ()
testFailedSend g = withSetup g $ \s@Setup {node, store} -> do
sender <- start s
setFault node "eth_sendRawTransaction" HttpFailure
Right p <- submitTransaction sender (TxCommit r1) fakeController (commit 1)
clearFault node "eth_sendRawTransaction"
sentTransactions node `shouldReturn` []
[NameTransaction {ntRaw, ntHash}] <- withTransaction store pendingTransactions
ntHash `shouldBe` ptHash p
followTransactions sender
sentTransactions node `shouldReturn` [ntRaw]
known s (ptHash p) `shouldReturn` True
testFeeBump :: TVar ChaChaDRG -> IO ()
testFeeBump g = withSetup g $ \s@Setup {node, store} -> do
sender <- start s
Right p <- submitTransaction sender (TxCommit r1) fakeController (commit 1)
[firstRaw] <- sentTransactions node
Right first@TxRequest {trMaxFeePerGas = firstMax, trMaxPriorityFeePerGas = firstTip} <- pure $ decodeSignedTx firstRaw
(firstTip, firstMax) `shouldBe` (fakeTip, 2 * fakeBaseFee + fakeTip)
passTime s $ replaceAfter - 1
followTransactions sender
passTime s 1
followTransactions sender
length <$> sentTransactions node `shouldReturn` 1
setFees node fakeTip (2 * fakeBaseFee)
followTransactions sender
length <$> sentTransactions node `shouldReturn` 1
passTime s replaceAfter
followTransactions sender
[_, bumpedRaw] <- sentTransactions node
let bumpedHash = TxHash $ C.keccak256 bumpedRaw
decodeSignedTx bumpedRaw `shouldBe` Right first {trMaxPriorityFeePerGas = fakeTip + fakeTip `div` 8 + 1, trMaxFeePerGas = 4 * fakeBaseFee + fakeTip}
known s (ptHash p) `shouldReturn` False
known s bumpedHash `shouldReturn` True
map (\(h, status, _) -> (h, status)) <$> statuses store r1 `shouldReturn` [(ptHash p, TSPending), (bumpedHash, TSPending)]
mineHash node bumpedHash
_ <- mine node []
followTransactions sender
TOConfirmed minedHash Receipt {receiptSuccess = True, receiptBlock} <- outcomeOf p
minedHash `shouldBe` bumpedHash
statuses store r1 `shouldReturn` [(ptHash p, TSDropped, Nothing), (bumpedHash, TSMined, Just receiptBlock)]
testRestartRebroadcast :: TVar ChaChaDRG -> IO ()
testRestartRebroadcast g = withSetup g $ \s@Setup {node, store} -> do
crashed <- start s
Right p <- submitTransaction crashed (TxCommit r1) fakeController (commit 1)
[raw] <- sentTransactions node
let TxHash h = ptHash p
dropTransaction node h
restarted <- start s
Just resumed <- inFlightTransaction restarted (TxCommit r1)
(ptHash resumed, ptNonce resumed) `shouldBe` (ptHash p, 0)
followTransactions restarted
sentTransactions node `shouldReturn` [raw, raw]
followTransactions restarted
sentTransactions node `shouldReturn` [raw, raw]
Right next <- submitTransaction restarted (TxCommit r2) fakeController (commit 2)
ptNonce next `shouldBe` 1
_ <- mine node [(h, True)]
_ <- mine node []
followTransactions restarted
outcomeOf resumed >>= (`shouldSatisfy` confirmedAs (ptHash p))
map (\(_, status, _) -> status) <$> statuses store r1 `shouldReturn` [TSMined]
testDroppedNonceUsed :: TVar ChaChaDRG -> IO ()
testDroppedNonceUsed g =
forM_ [\node h -> dropTransaction node h >> useNextNonce node, \node h -> mine node [(h, True)] >> pruneReceipt node h] $ \lose ->
withSetup g $ \s@Setup {node, store} -> do
sender <- start s
Right p <- submitTransaction sender (TxCommit r1) fakeController (commit 1)
let TxHash h = ptHash p
lose node h
followTransactions sender
settled sender (TxCommit r1) `shouldReturn` False
_ <- mine node []
followTransactions sender
outcomeOf p `shouldReturn` TONonceUsed
statuses store r1 `shouldReturn` [(ptHash p, TSDropped, Nothing)]
length <$> sentTransactions node `shouldReturn` 1
Right again <- submitTransaction sender (TxCommit r1) fakeController (commit 1)
ptNonce again `shouldBe` 1
length <$> sentTransactions node `shouldReturn` 2
testFailedRound :: TVar ChaChaDRG -> IO ()
testFailedRound g = withSetup g $ \s@Setup {node, store} -> do
sender <- start s
Right p <- submitTransaction sender (TxCommit r1) fakeController (commit 1)
mineHash node (ptHash p)
_ <- mine node []
renameTransactions store "sx_badge_service_name_transactions" "name_transactions_away"
senderRound sender
settled sender (TxCommit r1) `shouldReturn` False
renameTransactions store "name_transactions_away" "sx_badge_service_name_transactions"
senderRound sender
outcomeOf p >>= (`shouldSatisfy` confirmedAs (ptHash p))
map (\(_, status, _) -> status) <$> statuses store r1 `shouldReturn` [TSMined]
where
renameTransactions store from to = withTransaction store $ \db -> DB.execute_ db $ fromString $ "ALTER TABLE " <> from <> " RENAME TO " <> to
testRefusedSendLogged :: TVar ChaChaDRG -> IO ()
testRefusedSendLogged g = withSetup g $ \s@Setup {node} -> do
sender <- start s
-- the specs run in parallel, so this one's lines are told apart by a nonce no other spec reaches
replicateM_ 9 $ useNextNonce node
let underfunded = "insufficient funds for gas * price + value: balance 0, tx cost 4600000000000000, overshot 4600000000000000"
logged <- capturingStderr $ do
setFault node "eth_sendRawTransaction" $ RpcError (-32000) underfunded Nothing
Right p <- submitTransaction sender (TxCommit r1) fakeController (commit 1)
ptNonce p `shouldBe` 9
followTransactions sender
followTransactions sender
setFault node "eth_sendRawTransaction" HttpFailure
followTransactions sender
followTransactions sender
setFault node "eth_sendRawTransaction" $ RpcError (-32003) "Insufficient funds for gas * price + value" Nothing
followTransactions sender
followTransactions sender
clearFault node "eth_sendRawTransaction"
followTransactions sender
let linesWith tag message = length $ filter (\l -> tag `T.isPrefixOf` l && message `T.isInfixOf` l) $ T.lines logged
linesWith "[ERROR" "names sender: nonce 9: not sent: ChainUnavailable \"eth_sendRawTransaction: error -32000: insufficient funds" `shouldBe` 1
linesWith "[WARN" "names sender: nonce 9: not sent: ChainUnavailable \"eth_sendRawTransaction: HTTP 502\"" `shouldBe` 1
linesWith "[ERROR" "names sender: nonce 9: not sent: ChainUnavailable \"eth_sendRawTransaction: error -32003: Insufficient funds" `shouldBe` 1
linesWith "[" "names sender: nonce 9" `shouldBe` 3
linesWith "[" "names sender: rebroadcasting nonce 9" `shouldBe` 0
length <$> sentTransactions node `shouldReturn` 1
testFeeCapSubmit :: TVar ChaChaDRG -> IO ()
testFeeCapSubmit g = withSetup g $ \s@Setup {node, store} -> do
sender <- start s
setFees node fakeTip (fakeMaxFeePerGas - fakeTip + 1)
submitTransaction sender (TxCommit r1) fakeController (commit 1) `refusedWith` SEFeeAboveCap (fakeMaxFeePerGas + 1)
-- twice the base fee is past Word64, which would wrap to a near-zero fee
let hugeBaseFee = maxBound `div` 2 + 1 :: Word64
setFees node fakeTip hugeBaseFee
submitTransaction sender (TxCommit r1) fakeController (commit 1) `refusedWith` SEFeeAboveCap (toInteger hugeBaseFee + fakeTip)
withTransaction store pendingTransactions `shouldReturn` []
sentTransactions node `shouldReturn` []
let baseFee = fakeMaxFeePerGas `div` 2
setFees node fakeTip baseFee
Right p <- submitTransaction sender (TxCommit r1) fakeController (commit 1)
ptNonce p `shouldBe` 0
[raw] <- sentTransactions node
(\TxRequest {trMaxPriorityFeePerGas, trMaxFeePerGas} -> (trMaxPriorityFeePerGas, trMaxFeePerGas)) <$> decodeSignedTx raw `shouldBe` Right (fakeTip, fakeMaxFeePerGas)
testFeeCapReplace :: TVar ChaChaDRG -> IO ()
testFeeCapReplace g = withCapSetup cap g $ \s@Setup {node} -> do
sender <- start s
Right p <- submitTransaction sender (TxCommit r1) fakeController (commit 1)
[firstRaw] <- sentTransactions node
Right first <- pure $ decodeSignedTx firstRaw
trMaxFeePerGas first `shouldBe` 2 * fakeBaseFee + fakeTip
setFees node fakeTip (2 * fakeBaseFee)
passTime s replaceAfter
followTransactions sender
[_, bumpedRaw] <- sentTransactions node
decodeSignedTx bumpedRaw `shouldBe` Right first {trMaxPriorityFeePerGas = fakeTip + fakeTip `div` 8 + 1, trMaxFeePerGas = cap}
passTime s replaceAfter
followTransactions sender
length <$> sentTransactions node `shouldReturn` 2
let bumpedHash = C.keccak256 bumpedRaw
dropTransaction node bumpedHash
followTransactions sender
sentTransactions node `shouldReturn` [firstRaw, bumpedRaw, bumpedRaw]
(fmap ptHash <$> inFlightTransaction sender (TxCommit r1)) `shouldReturn` Just (TxHash bumpedHash)
ptNonce p `shouldBe` 0
where
-- above the first max fee and its bump, below the market's headroom fee and a second bump
cap = 2 * fakeBaseFee + fakeTip + 1000000000
-- fixtures
r1, r2 :: RegistrationId
r1 = RegistrationId "r1"
r2 = RegistrationId "r2"
commit :: Word8 -> ByteString
commit = commitCalldata . digestFixture
-- | viem's encodeErrorResult of InsufficientAllowance(10000, 2500)
insufficientAllowance :: ByteString
insufficientAllowance = unhex "2a1b2dd8000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000009c4"
mineHash :: FakeEthNode -> TxHash -> IO ()
mineHash node (TxHash h) = () <$ mine node [(h, True)]
confirmedAs :: TxHash -> TxOutcome -> Bool
confirmedAs hash = \case
TOConfirmed h Receipt {receiptSuccess = True} -> h == hash
_ -> False
outcomeOf :: PendingTx -> IO TxOutcome
outcomeOf p = awaitOutcome 2000000 p >>= maybe (fail "the transaction is not settled") pure
settled :: Sender -> TxFor -> IO Bool
settled sender for = null <$> inFlightTransaction sender for
statuses :: DBStore -> RegistrationId -> IO [(TxHash, TxStatus, Maybe Word64)]
statuses store rid = withTransaction store $ \db -> map (\NameTransaction {ntHash, ntStatus, ntMinedBlock} -> (ntHash, ntStatus, ntMinedBlock)) <$> registrationTransactions db rid
known :: Setup -> TxHash -> IO Bool
known Setup {chain} h = either (error . show) id <$> transactionKnown chain h
refusedWith :: IO (Either SendError PendingTx) -> SendError -> Expectation
refusedWith submit expected =
submit >>= \case
Left e -> e `shouldBe` expected
Right p -> expectationFailure $ "sent with nonce " <> show (ptNonce p)
unhex :: ByteString -> ByteString
unhex = either error id . convertFromBase Base16