Skip to content

Commit

Permalink
assert
Browse files Browse the repository at this point in the history
  • Loading branch information
trinitys7 committed Nov 15, 2023
1 parent f96b077 commit 49a0d57
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions node/full_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ func TestMempoolDirectly(t *testing.T) {

node := initializeAndStartFullNode(ctx, t)
defer cleanUpNode(node, t)
assert := assert.New(t)

peerID := getPeerID(assert)
verifyTransactions(node, peerID, assert)
verifyMempoolSize(node, assert)
peerID := getPeerID(t)
verifyTransactions(t, node, peerID)
verifyMempoolSize(t, node)
}

// setupMockApplication initializes a mock application
Expand All @@ -54,27 +53,27 @@ func generateSingleKey() crypto.PrivKey {
}

// getPeerID generates a peer ID
func getPeerID(assert *assert.Assertions) peer.ID {
func getPeerID(t *testing.T) peer.ID {
key := generateSingleKey()
peerID, err := peer.IDFromPrivateKey(key)
assert.NoError(err)
assert.NoError(t, err)
return peerID
}

// verifyTransactions checks if transactions are valid
func verifyTransactions(node *FullNode, peerID peer.ID, assert *assert.Assertions) {
func verifyTransactions(t *testing.T, node *FullNode, peerID peer.ID) {
transactions := []string{"tx1", "tx2", "tx3", "tx4"}
for _, tx := range transactions {
err := node.Mempool.CheckTx([]byte(tx), func(r *abci.Response) {}, mempool.TxInfo{
SenderID: node.mempoolIDs.GetForPeer(peerID),
})
assert.NoError(err)
assert.NoError(t, err)
}
}

// verifyMempoolSize checks if the mempool size is as expected
func verifyMempoolSize(node *FullNode, assert *assert.Assertions) {
assert.NoError(testutils.Retry(300, 100*time.Millisecond, func() error {
func verifyMempoolSize(t *testing.T, node *FullNode) {
assert.NoError(t, testutils.Retry(300, 100*time.Millisecond, func() error {
expectedSize := int64(4 * len("tx*"))
actualSize := node.Mempool.SizeBytes()
if expectedSize == actualSize {
Expand Down

0 comments on commit 49a0d57

Please sign in to comment.