payloads_test.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. package vaa
  2. import (
  3. "bytes"
  4. "encoding/hex"
  5. "errors"
  6. "reflect"
  7. "testing"
  8. "time"
  9. "github.com/ethereum/go-ethereum/common"
  10. "github.com/holiman/uint256"
  11. "github.com/stretchr/testify/assert"
  12. "github.com/stretchr/testify/require"
  13. )
  14. var addr = Address{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4}
  15. var dummyBytes = [32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}
  16. func TestCoreModule(t *testing.T) {
  17. hexifiedCoreModule := "00000000000000000000000000000000000000000000000000000000436f7265"
  18. assert.Equal(t, hex.EncodeToString(CoreModule), hexifiedCoreModule)
  19. }
  20. func TestBodyContractUpgrade(t *testing.T) {
  21. test := BodyContractUpgrade{ChainID: 1, NewContract: addr}
  22. assert.Equal(t, test.ChainID, ChainID(1))
  23. assert.Equal(t, test.NewContract, addr)
  24. }
  25. func TestBodyGuardianSetUpdate(t *testing.T) {
  26. keys := []common.Address{
  27. common.HexToAddress("0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed"),
  28. common.HexToAddress("0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaee"),
  29. }
  30. test := BodyGuardianSetUpdate{Keys: keys, NewIndex: uint32(1)}
  31. assert.Equal(t, test.Keys, keys)
  32. assert.Equal(t, test.NewIndex, uint32(1))
  33. }
  34. func TestBodyTokenBridgeRegisterChain(t *testing.T) {
  35. module := "test"
  36. test := BodyTokenBridgeRegisterChain{Module: module, ChainID: 1, EmitterAddress: addr}
  37. assert.Equal(t, test.Module, module)
  38. assert.Equal(t, test.ChainID, ChainID(1))
  39. assert.Equal(t, test.EmitterAddress, addr)
  40. }
  41. func TestBodyTokenBridgeUpgradeContract(t *testing.T) {
  42. module := "test"
  43. test := BodyTokenBridgeUpgradeContract{Module: module, TargetChainID: 1, NewContract: addr}
  44. assert.Equal(t, test.Module, module)
  45. assert.Equal(t, test.TargetChainID, ChainID(1))
  46. assert.Equal(t, test.NewContract, addr)
  47. }
  48. func TestBodyContractUpgradeSerialize(t *testing.T) {
  49. bodyContractUpgrade := BodyContractUpgrade{ChainID: 1, NewContract: addr}
  50. expected := "00000000000000000000000000000000000000000000000000000000436f72650100010000000000000000000000000000000000000000000000000000000000000004"
  51. serializedBodyContractUpgrade, err := bodyContractUpgrade.Serialize()
  52. require.NoError(t, err)
  53. assert.Equal(t, expected, hex.EncodeToString(serializedBodyContractUpgrade))
  54. }
  55. func TestBodyGuardianSetUpdateSerialize(t *testing.T) {
  56. keys := []common.Address{
  57. common.HexToAddress("0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed"),
  58. common.HexToAddress("0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaee"),
  59. }
  60. bodyGuardianSetUpdate := BodyGuardianSetUpdate{Keys: keys, NewIndex: uint32(1)}
  61. expected := "00000000000000000000000000000000000000000000000000000000436f726502000000000001025aaeb6053f3e94c9b9a09f33669435e7ef1beaed5aaeb6053f3e94c9b9a09f33669435e7ef1beaee"
  62. serializedBodyGuardianSetUpdate, err := bodyGuardianSetUpdate.Serialize()
  63. require.NoError(t, err)
  64. assert.Equal(t, expected, hex.EncodeToString(serializedBodyGuardianSetUpdate))
  65. }
  66. func TestBodyTokenBridgeRegisterChainSerialize(t *testing.T) {
  67. module := "test"
  68. tests := []struct {
  69. name string
  70. expected string
  71. object BodyTokenBridgeRegisterChain
  72. err error
  73. }{
  74. {
  75. name: "working_as_expected",
  76. err: nil,
  77. object: BodyTokenBridgeRegisterChain{Module: module, ChainID: 1, EmitterAddress: addr},
  78. expected: "000000000000000000000000000000000000000000000000000000007465737401000000010000000000000000000000000000000000000000000000000000000000000004",
  79. },
  80. {
  81. name: "panic_at_the_disco!",
  82. err: errors.New("payload longer than 32 bytes"),
  83. object: BodyTokenBridgeRegisterChain{Module: "123456789012345678901234567890123", ChainID: 1, EmitterAddress: addr},
  84. expected: "payload longer than 32 bytes",
  85. },
  86. }
  87. for _, testCase := range tests {
  88. t.Run(testCase.name, func(t *testing.T) {
  89. buf, err := testCase.object.Serialize()
  90. if testCase.err != nil {
  91. require.ErrorContains(t, err, testCase.err.Error())
  92. assert.Nil(t, buf)
  93. } else {
  94. require.NoError(t, err)
  95. assert.Equal(t, testCase.expected, hex.EncodeToString(buf))
  96. }
  97. })
  98. }
  99. }
  100. func TestBodyTokenBridgeUpgradeContractSerialize(t *testing.T) {
  101. module := "test"
  102. bodyTokenBridgeUpgradeContract := BodyTokenBridgeUpgradeContract{Module: module, TargetChainID: 1, NewContract: addr}
  103. expected := "00000000000000000000000000000000000000000000000000000000746573740200010000000000000000000000000000000000000000000000000000000000000004"
  104. serializedBodyTokenBridgeUpgradeContract, err := bodyTokenBridgeUpgradeContract.Serialize()
  105. require.NoError(t, err)
  106. assert.Equal(t, expected, hex.EncodeToString(serializedBodyTokenBridgeUpgradeContract))
  107. }
  108. func TestBodyWormchainStoreCodeSerialize(t *testing.T) {
  109. expected := "0000000000000000000000000000000000000000005761736d644d6f64756c65010c200102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20"
  110. bodyWormchainStoreCode := BodyWormchainStoreCode{WasmHash: dummyBytes}
  111. buf, err := bodyWormchainStoreCode.Serialize()
  112. require.NoError(t, err)
  113. assert.Equal(t, expected, hex.EncodeToString(buf))
  114. }
  115. func TestBodyWormchainInstantiateContractSerialize(t *testing.T) {
  116. actual := BodyWormchainInstantiateContract{InstantiationParamsHash: dummyBytes}
  117. expected := "0000000000000000000000000000000000000000005761736d644d6f64756c65020c200102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20"
  118. buf, err := actual.Serialize()
  119. require.NoError(t, err)
  120. assert.Equal(t, expected, hex.EncodeToString(buf))
  121. }
  122. func TestBodyWormchainMigrateContractSerialize(t *testing.T) {
  123. actual := BodyWormchainMigrateContract{MigrationParamsHash: dummyBytes}
  124. expected := "0000000000000000000000000000000000000000005761736d644d6f64756c65030c200102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20"
  125. buf, err := actual.Serialize()
  126. require.NoError(t, err)
  127. assert.Equal(t, expected, hex.EncodeToString(buf))
  128. }
  129. func TestBodyWormchainWasmAllowlistInstantiateSerialize(t *testing.T) {
  130. actual := BodyWormchainWasmAllowlistInstantiate{ContractAddr: dummyBytes, CodeId: uint64(42)}
  131. expected := "0000000000000000000000000000000000000000005761736d644d6f64756c65040c200102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20000000000000002a"
  132. buf, err := actual.Serialize(ActionAddWasmInstantiateAllowlist)
  133. require.NoError(t, err)
  134. assert.Equal(t, expected, hex.EncodeToString(buf))
  135. }
  136. const BodyWormchainWasmAllowlistInstantiateBuf = "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20000000000000002a"
  137. func TestBodyWormchainWasmAllowlistInstantiateDeserialize(t *testing.T) {
  138. expected := BodyWormchainWasmAllowlistInstantiate{ContractAddr: dummyBytes, CodeId: uint64(42)}
  139. buf, err := hex.DecodeString(BodyWormchainWasmAllowlistInstantiateBuf)
  140. require.NoError(t, err)
  141. var actual BodyWormchainWasmAllowlistInstantiate
  142. err = actual.Deserialize(buf)
  143. require.NoError(t, err)
  144. assert.True(t, reflect.DeepEqual(expected, actual))
  145. }
  146. func TestBodyWormchainWasmAllowlistInstantiateDeserializeFailureTooShort(t *testing.T) {
  147. buf, err := hex.DecodeString(BodyWormchainWasmAllowlistInstantiateBuf[0 : len(BodyWormchainWasmAllowlistInstantiateBuf)-2])
  148. require.NoError(t, err)
  149. var actual BodyWormchainWasmAllowlistInstantiate
  150. err = actual.Deserialize(buf)
  151. require.ErrorContains(t, err, "incorrect payload length, should be 40, is 39")
  152. }
  153. func TestBodyWormchainWasmAllowlistInstantiateDeserializeFailureTooLong(t *testing.T) {
  154. buf, err := hex.DecodeString(BodyWormchainWasmAllowlistInstantiateBuf + "00")
  155. require.NoError(t, err)
  156. var actual BodyWormchainWasmAllowlistInstantiate
  157. err = actual.Deserialize(buf)
  158. require.ErrorContains(t, err, "incorrect payload length, should be 40, is 41")
  159. }
  160. func TestBodyCircleIntegrationUpdateWormholeFinalitySerialize(t *testing.T) {
  161. expected := "000000000000000000000000000000436972636c65496e746567726174696f6e0100022a"
  162. bodyCircleIntegrationUpdateWormholeFinality := BodyCircleIntegrationUpdateWormholeFinality{TargetChainID: ChainIDEthereum, Finality: 42}
  163. buf, err := bodyCircleIntegrationUpdateWormholeFinality.Serialize()
  164. require.NoError(t, err)
  165. assert.Equal(t, expected, hex.EncodeToString(buf))
  166. }
  167. func TestBodyCircleIntegrationRegisterEmitterAndDomainSerialize(t *testing.T) {
  168. expected := "000000000000000000000000000000436972636c65496e746567726174696f6e020002000600000000000000000000000000000000000000000000000000000000000000040000002a"
  169. bodyCircleIntegrationRegisterEmitterAndDomain := BodyCircleIntegrationRegisterEmitterAndDomain{
  170. TargetChainID: ChainIDEthereum,
  171. ForeignEmitterChainId: ChainIDAvalanche,
  172. ForeignEmitterAddress: addr,
  173. CircleDomain: 42,
  174. }
  175. buf, err := bodyCircleIntegrationRegisterEmitterAndDomain.Serialize()
  176. require.NoError(t, err)
  177. assert.Equal(t, expected, hex.EncodeToString(buf))
  178. }
  179. func TestBodyCircleIntegrationUpgradeContractImplementationSerialize(t *testing.T) {
  180. expected := "000000000000000000000000000000436972636c65496e746567726174696f6e0300020000000000000000000000000000000000000000000000000000000000000004"
  181. bodyCircleIntegrationUpgradeContractImplementation := BodyCircleIntegrationUpgradeContractImplementation{
  182. TargetChainID: ChainIDEthereum,
  183. NewImplementationAddress: addr,
  184. }
  185. buf, err := bodyCircleIntegrationUpgradeContractImplementation.Serialize()
  186. require.NoError(t, err)
  187. assert.Equal(t, expected, hex.EncodeToString(buf))
  188. }
  189. func TestBodyIbcReceiverUpdateChannelChain(t *testing.T) {
  190. expected := "0000000000000000000000000000000000000000004962635265636569766572010c20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006368616e6e656c2d300013"
  191. channelId, err := LeftPadIbcChannelId("channel-0")
  192. require.NoError(t, err)
  193. bodyIbcReceiverUpdateChannelChain := BodyIbcUpdateChannelChain{
  194. TargetChainId: ChainIDWormchain,
  195. ChannelId: channelId,
  196. ChainId: ChainIDInjective,
  197. }
  198. buf, err := bodyIbcReceiverUpdateChannelChain.Serialize(IbcReceiverModuleStr)
  199. require.NoError(t, err)
  200. assert.Equal(t, expected, hex.EncodeToString(buf))
  201. }
  202. func TestBodyIbcReceiverUpdateChannelChainBadModuleName(t *testing.T) {
  203. channelId, err := LeftPadIbcChannelId("channel-0")
  204. require.NoError(t, err)
  205. bodyIbcReceiverUpdateChannelChain := BodyIbcUpdateChannelChain{
  206. TargetChainId: ChainIDWormchain,
  207. ChannelId: channelId,
  208. ChainId: ChainIDInjective,
  209. }
  210. buf, err := bodyIbcReceiverUpdateChannelChain.Serialize(IbcReceiverModuleStr + "ExtraJunk")
  211. require.ErrorContains(t, err, "module for BodyIbcUpdateChannelChain must be either IbcReceiver or IbcTranslator")
  212. assert.Nil(t, buf)
  213. }
  214. func TestLeftPadIbcChannelId(t *testing.T) {
  215. channelId, err := LeftPadIbcChannelId("channel-0")
  216. require.NoError(t, err)
  217. assert.Equal(t, "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006368616e6e656c2d30", hex.EncodeToString(channelId[:]))
  218. }
  219. func TestLeftPadIbcChannelIdFailureTooLong(t *testing.T) {
  220. channelId, err := LeftPadIbcChannelId("channel-ThatIsTooLong!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
  221. require.ErrorContains(t, err, "failed to left pad module: payload longer than 64 bytes")
  222. expected := [64]byte{}
  223. assert.True(t, bytes.Equal(expected[:], channelId[:]))
  224. }
  225. func TestLeftPadBytes(t *testing.T) {
  226. payload := "AAAA"
  227. paddedPayload, err := LeftPadBytes(payload, int(8))
  228. require.NoError(t, err)
  229. buf := &bytes.Buffer{}
  230. buf.WriteByte(0x00)
  231. buf.WriteByte(0x00)
  232. buf.WriteByte(0x00)
  233. buf.WriteByte(0x00)
  234. buf.Write([]byte(payload))
  235. assert.Equal(t, paddedPayload, buf)
  236. }
  237. func TestLeftPadBytesFailures(t *testing.T) {
  238. payload := "AAAA"
  239. paddedPayload, err := LeftPadBytes(payload, int(-2))
  240. require.ErrorContains(t, err, "cannot prepend bytes to a negative length buffer")
  241. assert.Nil(t, paddedPayload)
  242. paddedPayload, err = LeftPadBytes(payload, int(2))
  243. require.ErrorContains(t, err, "payload longer than 2 bytes")
  244. assert.Nil(t, paddedPayload)
  245. }
  246. func TestSerializeBridgeGovernanceVaaModuleTooLong(t *testing.T) {
  247. buf, err := serializeBridgeGovernanceVaa("ModuleNameIsMoreThanThirtyTwoCharacters", ActionRegisterChain, 1, []byte{0, 1, 2})
  248. require.ErrorContains(t, err, "failed to left pad module: payload longer than 32 bytes")
  249. assert.Nil(t, buf)
  250. }
  251. func FuzzLeftPadBytes(f *testing.F) {
  252. // Add examples to our fuzz corpus
  253. f.Add("FOO", 8)
  254. f.Add("123", 8)
  255. f.Fuzz(func(t *testing.T, payload string, length int) {
  256. // We know length could be negative, but we panic if it is in the implementation
  257. if length < 0 {
  258. t.Skip()
  259. }
  260. // We know we cannot left pad something shorter than the payload being provided, but we panic if it is
  261. if len(payload) > length {
  262. t.Skip()
  263. }
  264. paddedPayload, err := LeftPadBytes(payload, length)
  265. require.NoError(t, err)
  266. // paddedPayload must always be equal to length
  267. assert.Equal(t, paddedPayload.Len(), length)
  268. })
  269. }
  270. func TestBodyWormholeRelayerSetDefaultDeliveryProviderSerialize(t *testing.T) {
  271. expected := "0000000000000000000000000000000000576f726d686f6c6552656c617965720300040000000000000000000000000000000000000000000000000000000000000004"
  272. bodyWormholeRelayerSetDefaultDeliveryProvider := BodyWormholeRelayerSetDefaultDeliveryProvider{
  273. ChainID: 4,
  274. NewDefaultDeliveryProviderAddress: addr,
  275. }
  276. buf, err := bodyWormholeRelayerSetDefaultDeliveryProvider.Serialize()
  277. require.NoError(t, err)
  278. assert.Equal(t, expected, hex.EncodeToString(buf))
  279. }
  280. func TestBodyGatewayIbcComposabilityMwContractSerialize(t *testing.T) {
  281. expected := "00000000000000000000000000000000000000476174657761794d6f64756c65030c200102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20"
  282. bodyGatewayIbcComposabilityMwContract := BodyGatewayIbcComposabilityMwContract{
  283. ContractAddr: dummyBytes,
  284. }
  285. buf, err := bodyGatewayIbcComposabilityMwContract.Serialize()
  286. require.NoError(t, err)
  287. assert.Equal(t, expected, hex.EncodeToString(buf))
  288. }
  289. const BodyGatewayIbcComposabilityMwContractBuf = "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20"
  290. func TestBodyGatewayIbcComposabilityMwContractDeserialize(t *testing.T) {
  291. expected := BodyGatewayIbcComposabilityMwContract{
  292. ContractAddr: dummyBytes,
  293. }
  294. var payloadBody BodyGatewayIbcComposabilityMwContract
  295. err := payloadBody.Deserialize(dummyBytes[:])
  296. require.NoError(t, err)
  297. assert.Equal(t, expected, payloadBody)
  298. }
  299. func TestBodyGatewayIbcComposabilityMwContractDeserializeFailureTooShort(t *testing.T) {
  300. buf, err := hex.DecodeString(BodyGatewayIbcComposabilityMwContractBuf[0 : len(BodyGatewayIbcComposabilityMwContractBuf)-2])
  301. require.NoError(t, err)
  302. var actual BodyGatewayIbcComposabilityMwContract
  303. err = actual.Deserialize(buf)
  304. require.ErrorContains(t, err, "incorrect payload length, should be 32, is 31")
  305. }
  306. func TestBodyGatewayIbcComposabilityMwContractDeserializeFailureTooLong(t *testing.T) {
  307. buf, err := hex.DecodeString(BodyGatewayIbcComposabilityMwContractBuf + "00")
  308. require.NoError(t, err)
  309. var actual BodyGatewayIbcComposabilityMwContract
  310. err = actual.Deserialize(buf)
  311. require.ErrorContains(t, err, "incorrect payload length, should be 32, is 33")
  312. }
  313. func TestBodySlashingParamsUpdateSerialize(t *testing.T) {
  314. signedBlocksWindow := uint64(100)
  315. minSignedPerWindow := uint64(500000000000000000)
  316. downtimeJailDuration := uint64(600 * time.Second)
  317. slashFractionDoubleSign := uint64(50000000000000000)
  318. slashFractionDowntime := uint64(10000000000000000)
  319. bodySlashingParamsUpdate := BodyGatewaySlashingParamsUpdate{
  320. SignedBlocksWindow: signedBlocksWindow,
  321. MinSignedPerWindow: minSignedPerWindow,
  322. DowntimeJailDuration: downtimeJailDuration,
  323. SlashFractionDoubleSign: slashFractionDoubleSign,
  324. SlashFractionDowntime: slashFractionDowntime,
  325. }
  326. serializedBody, err := bodySlashingParamsUpdate.Serialize()
  327. require.NoError(t, err)
  328. expected := "00000000000000000000000000000000000000476174657761794d6f64756c65040c20000000000000006406f05b59d3b200000000008bb2c9700000b1a2bc2ec50000002386f26fc10000"
  329. assert.Equal(t, expected, hex.EncodeToString(serializedBody))
  330. }
  331. const BodySlashingParamsUpdateBuf = "000000000000006406f05b59d3b200000000008bb2c9700000b1a2bc2ec50000002386f26fc10000"
  332. func TestBodySlashingParamsUpdateDeserialize(t *testing.T) {
  333. expected := BodyGatewaySlashingParamsUpdate{
  334. SignedBlocksWindow: 100,
  335. MinSignedPerWindow: 500000000000000000,
  336. DowntimeJailDuration: uint64(600 * time.Second),
  337. SlashFractionDoubleSign: 50000000000000000,
  338. SlashFractionDowntime: 10000000000000000,
  339. }
  340. var payloadBody BodyGatewaySlashingParamsUpdate
  341. bz, err := hex.DecodeString(BodySlashingParamsUpdateBuf)
  342. require.NoError(t, err)
  343. err = payloadBody.Deserialize(bz)
  344. require.NoError(t, err)
  345. assert.Equal(t, expected, payloadBody)
  346. }
  347. func TestBodySlashingParamsUpdateDeserializeFailureTooShort(t *testing.T) {
  348. buf, err := hex.DecodeString(BodySlashingParamsUpdateBuf[0 : len(BodySlashingParamsUpdateBuf)-2])
  349. require.NoError(t, err)
  350. var actual BodyGatewaySlashingParamsUpdate
  351. err = actual.Deserialize(buf)
  352. require.ErrorContains(t, err, "incorrect payload length, should be 40, is 39")
  353. }
  354. func TestBodySlashingParamsUpdateDeserializeFailureTooLong(t *testing.T) {
  355. buf, err := hex.DecodeString(BodySlashingParamsUpdateBuf + "00")
  356. require.NoError(t, err)
  357. var actual BodyGatewaySlashingParamsUpdate
  358. err = actual.Deserialize(buf)
  359. require.ErrorContains(t, err, "incorrect payload length, should be 40, is 41")
  360. }
  361. func TestBodyCoreRecoverChainIdSerialize(t *testing.T) {
  362. expected := "00000000000000000000000000000000000000000000000000000000436f72650500000000000000000000000000000000000000000000000000000000000000010fa0"
  363. BodyRecoverChainId := BodyRecoverChainId{
  364. Module: "Core",
  365. EvmChainID: uint256.NewInt(1),
  366. NewChainID: 4000,
  367. }
  368. buf, err := BodyRecoverChainId.Serialize()
  369. require.NoError(t, err)
  370. assert.Equal(t, expected, hex.EncodeToString(buf))
  371. }
  372. func TestBodyTokenBridgeRecoverChainIdSerialize(t *testing.T) {
  373. expected := "000000000000000000000000000000000000000000546f6b656e4272696467650300000000000000000000000000000000000000000000000000000000000000010fa0"
  374. BodyRecoverChainId := BodyRecoverChainId{
  375. Module: "TokenBridge",
  376. EvmChainID: uint256.NewInt(1),
  377. NewChainID: 4000,
  378. }
  379. buf, err := BodyRecoverChainId.Serialize()
  380. require.NoError(t, err)
  381. assert.Equal(t, expected, hex.EncodeToString(buf))
  382. }
  383. func TestBodyRecoverChainIdModuleTooLong(t *testing.T) {
  384. BodyRecoverChainId := BodyRecoverChainId{
  385. Module: "ModuleNameIsMoreThanThirtyTwoCharacters",
  386. EvmChainID: uint256.NewInt(1),
  387. NewChainID: 4000,
  388. }
  389. buf, err := BodyRecoverChainId.Serialize()
  390. require.ErrorContains(t, err, "failed to left pad module: payload longer than 32 bytes")
  391. assert.Nil(t, buf)
  392. }
  393. func TestBodyCoreBridgeSetMessageFeeSerialize(t *testing.T) {
  394. expected := "00000000000000000000000000000000000000000000000000000000436f72650304560000000000000000000000000000000000000000000000000000000000000123"
  395. bodyCoreBridgeSetMessageFee := BodyCoreBridgeSetMessageFee{
  396. ChainID: 0x456,
  397. MessageFee: uint256.NewInt(0x123),
  398. }
  399. buf, err := bodyCoreBridgeSetMessageFee.Serialize()
  400. require.NoError(t, err)
  401. assert.Equal(t, expected, hex.EncodeToString(buf))
  402. }