Skip to content

Commit

Permalink
fix TestMempoolEthTxsAppGossipHandling (ava-labs#629)
Browse files Browse the repository at this point in the history
* fix TestMempoolEthTxsAppGossipHandling

* Update plugin/evm/gossiper_eth_gossiping_test.go

Signed-off-by: Darioush Jalali <darioush.jalali@avalabs.org>

* fix atomic test too

---------

Signed-off-by: Darioush Jalali <darioush.jalali@avalabs.org>
  • Loading branch information
darioush authored and oxbee committed Nov 6, 2024
1 parent 0001c8e commit cd694a2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 25 deletions.
16 changes: 5 additions & 11 deletions plugin/evm/gossiper_atomic_gossiping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,13 @@ func TestMempoolAtmTxsAppGossipHandlingDiscardedTx(t *testing.T) {

assert.False(mempool.has(txID))

// Gossip the transaction that conflicts with the originally
// discarded tx and ensure it is accepted into the mempool and gossipped
// to the network.
nodeID = ids.GenerateTestNodeID()
msg = message.AtomicTxGossip{
Tx: conflictingTx.SignedBytes(),
}
msgBytes, err = message.BuildGossipMessage(vm.networkCodec, msg)
assert.NoError(err)

vm.ctx.Lock.Unlock()

assert.NoError(vm.AppGossip(context.Background(), nodeID, msgBytes))
// Conflicting tx must be submitted over the API to be included in push gossip.
// (i.e., txs received via p2p are not included in push gossip)
// This test adds it directly to the mempool + gossiper to simulate that.
vm.mempool.AddTx(conflictingTx)
vm.atomicTxPushGossiper.Add(&GossipAtomicTx{conflictingTx})
time.Sleep(500 * time.Millisecond)

vm.ctx.Lock.Lock()
Expand Down
16 changes: 3 additions & 13 deletions plugin/evm/gossiper_eth_gossiping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"

"github.com/stretchr/testify/assert"

"github.com/ava-labs/coreth/core"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/params"
"github.com/ava-labs/coreth/plugin/evm/message"
)

func fundAddressByGenesis(addrs []common.Address) (string, error) {
Expand Down Expand Up @@ -115,17 +113,9 @@ func TestMempoolEthTxsAppGossipHandling(t *testing.T) {
// prepare a tx
tx := getValidEthTxs(key, 1, common.Big1)[0]

// show that unknown coreth hashes is requested
txBytes, err := rlp.EncodeToBytes([]*types.Transaction{tx})
assert.NoError(err)
msg := message.EthTxsGossip{
Txs: txBytes,
}
msgBytes, err := message.BuildGossipMessage(vm.networkCodec, msg)
assert.NoError(err)

nodeID := ids.GenerateTestNodeID()
err = vm.AppGossip(context.Background(), nodeID, msgBytes)
// Txs must be submitted over the API to be included in push gossip.
// (i.e., txs received via p2p are not included in push gossip)
err = vm.eth.APIBackend.SendTx(context.Background(), tx)
assert.NoError(err)
assert.False(txRequested, "tx should not be requested")

Expand Down
1 change: 0 additions & 1 deletion plugin/evm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ func GenesisVMWithClock(
*enginetest.Sender,
) {
vm := &VM{clock: clock}
vm.p2pSender = &enginetest.SenderStub{}
ctx, dbManager, genesisBytes, issuer, m := setupGenesis(t, genesisJSON)
appSender := &enginetest.Sender{T: t}
appSender.CantSendAppGossip = true
Expand Down

0 comments on commit cd694a2

Please # to comment.