github.com/dim4egster/coreth@v0.10.2/plugin/evm/message/message_test.go (about) 1 // (c) 2019-2021, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package message 5 6 import ( 7 "encoding/base64" 8 "testing" 9 10 "github.com/dim4egster/qmallgo/utils" 11 "github.com/dim4egster/qmallgo/utils/units" 12 13 "github.com/stretchr/testify/assert" 14 ) 15 16 // TestMarshalAtomicTx asserts that the structure or serialization logic hasn't changed, primarily to 17 // ensure compatibility with the network. 18 func TestMarshalAtomicTx(t *testing.T) { 19 assert := assert.New(t) 20 21 base64AtomicTxGossip := "AAAAAAAAAAAABGJsYWg=" 22 msg := []byte("blah") 23 builtMsg := AtomicTxGossip{ 24 Tx: msg, 25 } 26 builtMsgBytes, err := BuildGossipMessage(Codec, builtMsg) 27 assert.NoError(err) 28 assert.Equal(base64AtomicTxGossip, base64.StdEncoding.EncodeToString(builtMsgBytes)) 29 30 parsedMsgIntf, err := ParseGossipMessage(Codec, builtMsgBytes) 31 assert.NoError(err) 32 33 parsedMsg, ok := parsedMsgIntf.(AtomicTxGossip) 34 assert.True(ok) 35 36 assert.Equal(msg, parsedMsg.Tx) 37 } 38 39 // TestMarshalEthTxs asserts that the structure or serialization logic hasn't changed, primarily to 40 // ensure compatibility with the network. 41 func TestMarshalEthTxs(t *testing.T) { 42 assert := assert.New(t) 43 44 base64EthTxGossip := "AAAAAAABAAAABGJsYWg=" 45 msg := []byte("blah") 46 builtMsg := EthTxsGossip{ 47 Txs: msg, 48 } 49 builtMsgBytes, err := BuildGossipMessage(Codec, builtMsg) 50 assert.NoError(err) 51 assert.Equal(base64EthTxGossip, base64.StdEncoding.EncodeToString(builtMsgBytes)) 52 53 parsedMsgIntf, err := ParseGossipMessage(Codec, builtMsgBytes) 54 assert.NoError(err) 55 56 parsedMsg, ok := parsedMsgIntf.(EthTxsGossip) 57 assert.True(ok) 58 59 assert.Equal(msg, parsedMsg.Txs) 60 } 61 62 func TestEthTxsTooLarge(t *testing.T) { 63 assert := assert.New(t) 64 65 builtMsg := EthTxsGossip{ 66 Txs: utils.RandomBytes(1024 * units.KiB), 67 } 68 _, err := BuildGossipMessage(Codec, builtMsg) 69 assert.Error(err) 70 } 71 72 func TestParseGibberish(t *testing.T) { 73 assert := assert.New(t) 74 75 randomBytes := utils.RandomBytes(256 * units.KiB) 76 _, err := ParseGossipMessage(Codec, randomBytes) 77 assert.Error(err) 78 }