diff --git a/rpc/block_test.go b/rpc/block_test.go index e1fd247d..f40b7e7f 100644 --- a/rpc/block_test.go +++ b/rpc/block_test.go @@ -106,7 +106,7 @@ func TestBlockHashAndNumber(t *testing.T) { // // The function takes a testing.T object as a parameter and initializes a testConfig object. // It defines a testSetType struct that contains several fields including BlockID, ExpectedError, ExpectedBlockWithTxHashes, and ExpectedPendingBlockWithTxHashes. -// The function then initializes a blockGoerli310370 variable of type BlockTxHashes with a predefined set of values. +// The function then initializes a blockSepolia30436 variable of type BlockTxHashes with a predefined set of values. // It also initializes a txHashes variable of type []felt.Felt and a blockHash variable of type felt.Felt. // // The function defines a testSet map that has three keys: "mock", "testnet", and "mainnet". @@ -139,44 +139,28 @@ func TestBlockWithTxHashes(t *testing.T) { ExpectedPendingBlockWithTxHashes *PendingBlockTxHashes } - var blockGoerli310370 = BlockTxHashes{ + var blockSepolia30436 = BlockTxHashes{ BlockHeader: BlockHeader{ - BlockHash: utils.TestHexToFelt(t, "0x6c2fe3db009a2e008c2d65fca14204f3405cb74742fcf685f02473acaf70c72"), - ParentHash: utils.TestHexToFelt(t, "0x1ce6fa8ef59dfa1ad8f7ce7c3a4e6752e2d8ae6274f8257345f680e6ae0b5b5"), - SequencerAddress: utils.TestHexToFelt(t, "0x46a89ae102987331d369645031b49c27738ed096f2789c24449966da4c6de6b"), - BlockNumber: 310370, - NewRoot: utils.TestHexToFelt(t, "0x5cd7a08312635206c0210b8c90e61ceac27cb09629064e12266fd79e4c05a3d"), - Timestamp: 1661450764, + BlockHash: utils.TestHexToFelt(t, "0x2488a7149327b4dcd200f05a131911bd44f946021539648642eaa7d6e82f289"), + ParentHash: utils.TestHexToFelt(t, "0x2adc07a26d70e72a16775e26c45074f0216bc2e86e35bfe53743968480e4c1b"), + SequencerAddress: utils.TestHexToFelt(t, "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"), + BlockNumber: 30436, + NewRoot: utils.TestHexToFelt(t, "0x4bbb6bec9488d70d9c9e96862cf50e22331a5e8d7b33a56712f56cd04c16e06"), + Timestamp: 1707158969, }, Status: "ACCEPTED_ON_L1", Transactions: utils.TestHexArrToFelt(t, []string{ - "0x40c82f79dd2bc1953fc9b347a3e7ab40fe218ed5740bf4e120f74e8a3c9ac99", - "0x28981b14353a28bc46758dff412ac544d16f2ffc8dde31867855592ea054ab1", - "0x41176c650076712f1618a141fc1cf9a8c39f0d9548a3458f29cf363310a1e72", - "0x43cd66f3ddbfbf681ab99bb57bf9d94c83d6e9b586bdbde78ab2deb0328ebd5", - "0x7602cfebe4f3cb3ef4c8b8c6d7dda2efaf4a500723020066f5db50acd5095cd", - "0x2612f3f870ee7e7617d4f9efdc41fa8fd571f9720b059b1aa14c1bf15d3a92a", - "0x1a7810a6c68adf0621ed384d915409c936efa0c9d436683ea0cf7ea171719b", - "0x26683aeef3e9d9bcc1f0d45a5f0b67d0aa1919726524b2a8dc59504dacfd1f4", - "0x1d374aa073435cdde1ec1caf972f7c175fd23438bb220848e71720e00fd7474", - "0xfc13eabaa2f38981e68bb010370cad7a7d0b65a59101ec816042adca0d6841", - "0x672d007224128b99bcc145cd3dbd8930a944b6a5fff5c27e3b158a6ff701509", - "0x24795cbca6d2eba941082cea3f686bc86ef27dd46fdf84b32f9ba25bbeddb28", - "0x69281a4dd58c260a06b3266554c0cf1a4f19b79d8488efef2a1f003d67506ed", - "0x62211cc3c94d612b580eb729410e52277f838f962d91af91fb2b0526704c04d", - "0x5e4128b7680db32de4dff7bc57cb11c9f222752b1f875e84b29785b4c284e2a", - "0xdb8ad2b7d008fd2ad7fba4315b193032dee85e17346c80276a2e08c7f09f80", - "0x67b9541ca879abc29fa24a0fa070285d1899fc044159521c827f6b6aa09bbd6", - "0x5d9c0ab1d4ed6e9376c8ab45ee02b25dd0adced12941aafe8ce37369d19d9c2", - "0x4e52da53e23d92d9818908aeb104b007ea24d3cd4a5aa43144d2db1011e314f", - "0x6cc05f5ab469a3675acb5885c274d5143dca75dd9835c582f59e85ab0642d39", - "0x561ed983d1d9c37c964a96f80ccaf3de772e2b73106d6f49dd7c3f7ed8483d9", + "0x10d2059db6d261fee740b515ed8b9c50955f03dd43c4729b24dc63278641926", + "0x50d39b3fd4931343aeb6bf325493f7b8c05d8bf2819e4dad465e42751e2412", + "0x3761dfe1ce22d16eab6339d8ba2ab4c56008182d979979f8e68217920193996", + "0x7e3f4756d90b1f6f8249185857b4beab0c0dd3d3b207ad73fd249c6267ecea5", }), } txHashes := utils.TestHexArrToFelt(t, []string{ - "0x40c82f79dd2bc1953fc9b347a3e7ab40fe218ed5740bf4e120f74e8a3c9ac99", - "0x28981b14353a28bc46758dff412ac544d16f2ffc8dde31867855592ea054ab1", + "0x10d2059db6d261fee740b515ed8b9c50955f03dd43c4729b24dc63278641926", + "0x50d39b3fd4931343aeb6bf325493f7b8c05d8bf2819e4dad465e42751e2412", + "0x3761dfe1ce22d16eab6339d8ba2ab4c56008182d979979f8e68217920193996", }) blockHash := utils.TestHexToFelt(t, "0xbeef") @@ -212,14 +196,14 @@ func TestBlockWithTxHashes(t *testing.T) { ExpectedErr: nil, }, { - BlockID: WithBlockHash(utils.TestHexToFelt(t, "0x6c2fe3db009a2e008c2d65fca14204f3405cb74742fcf685f02473acaf70c72")), + BlockID: WithBlockHash(utils.TestHexToFelt(t, "0x2488a7149327b4dcd200f05a131911bd44f946021539648642eaa7d6e82f289")), ExpectedErr: nil, - ExpectedBlockWithTxHashes: &blockGoerli310370, + ExpectedBlockWithTxHashes: &blockSepolia30436, }, { - BlockID: WithBlockNumber(310370), + BlockID: WithBlockNumber(30436), ExpectedErr: nil, - ExpectedBlockWithTxHashes: &blockGoerli310370, + ExpectedBlockWithTxHashes: &blockSepolia30436, }, }, "mainnet": {}, @@ -277,7 +261,7 @@ func TestBlockWithTxHashes(t *testing.T) { // TestBlockWithTxsAndInvokeTXNV0 tests the BlockWithTxsAndInvokeTXNV0 function. // // The function tests the BlockWithTxsAndInvokeTXNV0 function by setting up a test configuration and a test set type. -// It then initializes a fullBlockGoerli310370 variable with a Block struct and invokes the BlockWithTxs function with different test scenarios. +// It then initializes a fullBlockSepolia30436 variable with a Block struct and invokes the BlockWithTxs function with different test scenarios. // The function compares the expected error with the actual error and checks if the BlockWithTxs function returns the correct block data. // It also verifies the block hash, the number of transactions in the block, and the details of a specific transaction. // @@ -286,7 +270,141 @@ func TestBlockWithTxHashes(t *testing.T) { // Returns: // // none -func TestBlockWithTxsAndInvokeTXNV0(t *testing.T) { +// +// Todo: Find a V0 transaction on SN_SEPOLIA +// func TestBlockWithTxsAndInvokeTXNV0(t *testing.T) { +// testConfig := beforeEach(t) + +// type testSetType struct { +// BlockID BlockID +// ExpectedError error +// LookupTxnPositionInOriginal int +// LookupTxnPositionInExpected int +// want *Block +// } + +// var fullBlockSepolia30436 = Block{ +// BlockHeader: BlockHeader{ +// BlockHash: utils.TestHexToFelt(t, "0x2488a7149327b4dcd200f05a131911bd44f946021539648642eaa7d6e82f289"), +// ParentHash: utils.TestHexToFelt(t, "0x2adc07a26d70e72a16775e26c45074f0216bc2e86e35bfe53743968480e4c1b"), +// SequencerAddress: utils.TestHexToFelt(t, "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"), +// BlockNumber: 30436, +// NewRoot: utils.TestHexToFelt(t, "0x4bbb6bec9488d70d9c9e96862cf50e22331a5e8d7b33a56712f56cd04c16e06"), +// Timestamp: 1661450764, +// }, +// Status: "ACCEPTED_ON_L1", +// Transactions: []BlockTransaction{ + +// BlockInvokeTxnV0{ +// TransactionHash: utils.TestHexToFelt(t, "0x10d2059db6d261fee740b515ed8b9c50955f03dd43c4729b24dc63278641926"), +// InvokeTxnV0: InvokeTxnV0{ +// Type: "INVOKE", +// MaxFee: utils.TestHexToFelt(t, "0x470de4df820000"), +// Version: TransactionV0, +// Signature: []*felt.Felt{ +// utils.TestHexToFelt(t, "0x7fb440b1dee35c5259bf10d55782bc973434d195bb5c8b95ac7d3d8e2a8a0e4"), +// utils.TestHexToFelt(t, "0x13089e5f38de4ea98e9275be7fadc915946be15c14a8fed7c55202818527bea"), +// }, +// FunctionCall: FunctionCall{ +// ContractAddress: nil, +// EntryPointSelector: nil, +// Calldata: []*felt.Felt{ +// utils.TestHexToFelt(t, "0x1"), +// utils.TestHexToFelt(t, "0x3fe8e4571772bbe0065e271686bd655efd1365a5d6858981e582f82f2c10313"), +// utils.TestHexToFelt(t, "0x2468d193cd15b621b24c2a602b8dbcfa5eaa14f88416c40c09d7fd12592cb4b"), +// utils.TestHexToFelt(t, "0x0"), +// }, +// }, +// }, +// }, +// }, +// } + +// testSet := map[string][]testSetType{ +// "mock": {}, +// "testnet": { +// { +// BlockID: WithBlockTag("latest"), +// ExpectedError: nil, +// }, +// { +// BlockID: WithBlockHash(utils.TestHexToFelt(t, "0x2488a7149327b4dcd200f05a131911bd44f946021539648642eaa7d6e82f289")), +// ExpectedError: nil, +// want: &fullBlockSepolia30436, +// }, +// { +// BlockID: WithBlockNumber(30436), +// ExpectedError: nil, +// want: &fullBlockSepolia30436, +// }, +// }, +// "mainnet": {}, +// }[testEnv] + +// for i, test := range testSet { +// fmt.Println("Test case", i) +// fmt.Println("BlockID is", test.BlockID) +// fmt.Println("LookuptxnPositionInOriginal is", test.LookupTxnPositionInOriginal) +// spy := NewSpy(testConfig.provider.c) +// testConfig.provider.c = spy +// blockWithTxsInterface, err := testConfig.provider.BlockWithTxs(context.Background(), test.BlockID) +// if err != test.ExpectedError { +// t.Fatal("BlockWithTxHashes match the expected error:", err) +// } +// if test.ExpectedError != nil && blockWithTxsInterface == nil { +// continue +// } +// blockWithTxs, ok := blockWithTxsInterface.(*Block) +// if !ok { +// t.Fatalf("expecting *rpv02.Block, instead %T", blockWithTxsInterface) +// } +// _, err = spy.Compare(blockWithTxs, false) +// if err != nil { +// t.Fatal("expecting to match", err) +// } +// if !strings.HasPrefix(blockWithTxs.BlockHash.String(), "0x") { +// t.Fatal("Block Hash should start with \"0x\", instead", blockWithTxs.BlockHash) +// } + +// if len(blockWithTxs.Transactions) == 0 { +// t.Fatal("the number of transaction should not be 0") +// } + +// if test.want != nil { +// if (*test.want).BlockHash == &felt.Zero { +// continue +// } + +// invokeV0Want, ok := (*test.want).Transactions[test.LookupTxnPositionInExpected].(BlockInvokeTxnV0) +// if !ok { +// t.Fatal("expected invoke v0 transaction") +// } +// invokeV0Block, ok := blockWithTxs.Transactions[test.LookupTxnPositionInOriginal].(BlockInvokeTxnV0) +// if !ok { +// t.Fatal("expected invoke v0 transaction") +// } +// require.Equal(t, invokeV0Want.TransactionHash, invokeV0Block.TransactionHash, "expected equal TransactionHash") +// require.Equal(t, invokeV0Want.InvokeTxnV0.MaxFee, invokeV0Block.InvokeTxnV0.MaxFee, "expected equal maxfee") +// require.Equal(t, invokeV0Want.InvokeTxnV0.EntryPointSelector, invokeV0Block.InvokeTxnV0.EntryPointSelector, "expected equal eps") + +// } + +// } +// } + +// TestBlockWithTxsAndInvokeTXNV1 tests the BlockWithTxsAndInvokeTXNV1 function. +// +// The function tests the BlockWithTxsAndInvokeTXNV1 function by setting up a test configuration and a test set type. +// It then initializes a fullBlockSepolia30436 variable with a Block struct and invokes the BlockWithTxs function with different test scenarios. +// The function compares the expected error with the actual error and checks if the BlockWithTxs function returns the correct block data. +// It also verifies the block hash, the number of transactions in the block, and the details of a specific transaction. +// +// Parameters: +// - t: The t testing object +// Returns: +// +// none +func TestBlockWithTxsAndInvokeTXNV1(t *testing.T) { testConfig := beforeEach(t) type testSetType struct { @@ -297,42 +415,35 @@ func TestBlockWithTxsAndInvokeTXNV0(t *testing.T) { want *Block } - var fullBlockGoerli310370 = Block{ + var fullBlockSepolia30436 = Block{ BlockHeader: BlockHeader{ - BlockHash: utils.TestHexToFelt(t, "0x6c2fe3db009a2e008c2d65fca14204f3405cb74742fcf685f02473acaf70c72"), - ParentHash: utils.TestHexToFelt(t, "0x1ce6fa8ef59dfa1ad8f7ce7c3a4e6752e2d8ae6274f8257345f680e6ae0b5b5"), - SequencerAddress: utils.TestHexToFelt(t, "0x46a89ae102987331d369645031b49c27738ed096f2789c24449966da4c6de6b"), - BlockNumber: 310370, - NewRoot: utils.TestHexToFelt(t, "0x5cd7a08312635206c0210b8c90e61ceac27cb09629064e12266fd79e4c05a3d"), + BlockHash: utils.TestHexToFelt(t, "0x10d2059db6d261fee740b515ed8b9c50955f03dd43c4729b24dc63278641926"), + ParentHash: utils.TestHexToFelt(t, "0x2adc07a26d70e72a16775e26c45074f0216bc2e86e35bfe53743968480e4c1b"), + SequencerAddress: utils.TestHexToFelt(t, "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"), + BlockNumber: 30436, + NewRoot: utils.TestHexToFelt(t, "0x4bbb6bec9488d70d9c9e96862cf50e22331a5e8d7b33a56712f56cd04c16e06"), Timestamp: 1661450764, }, Status: "ACCEPTED_ON_L1", Transactions: []BlockTransaction{ - BlockInvokeTxnV0{ - TransactionHash: utils.TestHexToFelt(t, "0x40c82f79dd2bc1953fc9b347a3e7ab40fe218ed5740bf4e120f74e8a3c9ac99"), - InvokeTxnV0: InvokeTxnV0{ + BlockInvokeTxnV1{ + TransactionHash: utils.TestHexToFelt(t, "0x10d2059db6d261fee740b515ed8b9c50955f03dd43c4729b24dc63278641926"), + InvokeTxnV1: InvokeTxnV1{ Type: "INVOKE", - MaxFee: utils.TestHexToFelt(t, "0xde0b6b3a7640000"), - Version: TransactionV0, + Nonce: utils.TestHexToFelt(t, "0x12562"), + MaxFee: utils.TestHexToFelt(t, "0x470de4df820000"), + Version: TransactionV1, Signature: []*felt.Felt{ - utils.TestHexToFelt(t, "0x7bc0a22005a54ec6a005c1e89ab0201cbd0819621edd9fe4d5ef177a4ff33dd"), - utils.TestHexToFelt(t, "0x13089e5f38de4ea98e9275be7fadc915946be15c14a8fed7c55202818527bea"), + utils.TestHexToFelt(t, "0x7fb440b1dee35c5259bf10d55782bc973434d195bb5c8b95ac7d3d8e2a8a0e4"), + utils.TestHexToFelt(t, "0x3e16f111f8a22cb484b09d2554fca1e669cd540c5ad7cf2b9878071a9b95693"), }, - FunctionCall: FunctionCall{ - ContractAddress: utils.TestHexToFelt(t, "0x2e28403d7ee5e337b7d456327433f003aa875c29631906908900058c83d8cb6"), - EntryPointSelector: utils.TestHexToFelt(t, "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad"), - Calldata: []*felt.Felt{ - utils.TestHexToFelt(t, "0x1"), - utils.TestHexToFelt(t, "0x33830ce413e4c096eef81b5e6ffa9b9f5d963f57b8cd63c9ae4c839c383c1a6"), - utils.TestHexToFelt(t, "0x2db698626ed7f60212e1ce6e99afb796b6b423d239c3f0ecef23e840685e866"), - utils.TestHexToFelt(t, "0x0"), - utils.TestHexToFelt(t, "0x2"), - utils.TestHexToFelt(t, "0x2"), - utils.TestHexToFelt(t, "0x61c6e7484657e5dc8b21677ffa33e4406c0600bba06d12cf1048fdaa55bdbc3"), - utils.TestHexToFelt(t, "0x6307b990"), - utils.TestHexToFelt(t, "0x2b81"), - }, + SenderAddress: utils.TestHexToFelt(t, "0x35acd6dd6c5045d18ca6d0192af46b335a5402c02d41f46e4e77ea2c951d9a3"), + Calldata: []*felt.Felt{ + utils.TestHexToFelt(t, "0x1"), + utils.TestHexToFelt(t, "0x3fe8e4571772bbe0065e271686bd655efd1365a5d6858981e582f82f2c10313"), + utils.TestHexToFelt(t, "0x2468d193cd15b621b24c2a602b8dbcfa5eaa14f88416c40c09d7fd12592cb4b"), + utils.TestHexToFelt(t, "0x0"), }, }, }, @@ -347,14 +458,18 @@ func TestBlockWithTxsAndInvokeTXNV0(t *testing.T) { ExpectedError: nil, }, { - BlockID: WithBlockHash(utils.TestHexToFelt(t, "0x6c2fe3db009a2e008c2d65fca14204f3405cb74742fcf685f02473acaf70c72")), - ExpectedError: nil, - want: &fullBlockGoerli310370, + BlockID: WithBlockHash(utils.TestHexToFelt(t, "0x2488a7149327b4dcd200f05a131911bd44f946021539648642eaa7d6e82f289")), + LookupTxnPositionInExpected: 0, + LookupTxnPositionInOriginal: 0, + ExpectedError: nil, + want: &fullBlockSepolia30436, }, { - BlockID: WithBlockNumber(310370), - ExpectedError: nil, - want: &fullBlockGoerli310370, + BlockID: WithBlockNumber(30436), + LookupTxnPositionInExpected: 0, + LookupTxnPositionInOriginal: 0, + ExpectedError: nil, + want: &fullBlockSepolia30436, }, }, "mainnet": {}, @@ -391,27 +506,169 @@ func TestBlockWithTxsAndInvokeTXNV0(t *testing.T) { continue } - invokeV0Want, ok := (*test.want).Transactions[test.LookupTxnPositionInExpected].(BlockInvokeTxnV0) + invokeV1Want, ok := (*test.want).Transactions[test.LookupTxnPositionInExpected].(BlockInvokeTxnV1) if !ok { - t.Fatal("expected invoke v0 transaction") + t.Fatal("expected invoke v1 transaction") } - invokeV0Block, ok := blockWithTxs.Transactions[test.LookupTxnPositionInOriginal].(BlockInvokeTxnV0) + invokeV1Block, ok := blockWithTxs.Transactions[test.LookupTxnPositionInOriginal].(BlockInvokeTxnV1) if !ok { - t.Fatal("expected invoke v0 transaction") + t.Fatal("expected invoke v1 transaction") } - require.Equal(t, invokeV0Want.TransactionHash, invokeV0Block.TransactionHash, "expected equal TransactionHash") - require.Equal(t, invokeV0Want.InvokeTxnV0.MaxFee, invokeV0Block.InvokeTxnV0.MaxFee, "expected equal maxfee") - require.Equal(t, invokeV0Want.InvokeTxnV0.EntryPointSelector, invokeV0Block.InvokeTxnV0.EntryPointSelector, "expected equal eps") + require.Equal(t, invokeV1Want.TransactionHash, invokeV1Block.TransactionHash, "expected equal TransactionHash") + require.Equal(t, invokeV1Want.InvokeTxnV1.MaxFee, invokeV1Block.InvokeTxnV1.MaxFee, "expected equal maxfee") + require.Equal(t, invokeV1Want.InvokeTxnV1.SenderAddress, invokeV1Block.InvokeTxnV1.SenderAddress, "expected equal senders addresses") + } + } +} + +// TestBlockWithTxsAndInvokeTXNV3 tests the BlockWithTxsAndInvokeTXNV3 function. +// +// The function tests the BlockWithTxsAndInvokeTXNV3 function by setting up a test configuration and a test set type. +// It then initializes a fullBlockSepolia52767 variable with a Block struct and invokes the BlockWithTxs function with different test scenarios. +// The function compares the expected error with the actual error and checks if the BlockWithTxs function returns the correct block data. +// It also verifies the block hash, the number of transactions in the block, and the details of a specific transaction. +// +// Parameters: +// - t: The t testing object +// Returns: +// +// none +func TestBlockWithTxsAndInvokeTXNV3(t *testing.T) { + testConfig := beforeEach(t) + + type testSetType struct { + BlockID BlockID + ExpectedError error + LookupTxnPositionInOriginal int + LookupTxnPositionInExpected int + want *Block + } + + var fullBlockSepolia52767 = Block{ + BlockHeader: BlockHeader{ + BlockHash: utils.TestHexToFelt(t, "0x4ae5d52c75e4dea5694f456069f830cfbc7bec70427eee170c3385f751b8564"), + ParentHash: utils.TestHexToFelt(t, "0x7d3a1bc98e49c197b38538fbc351dae6ed4f0ff4e718db119ddacef3088b928"), + SequencerAddress: utils.TestHexToFelt(t, "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"), + BlockNumber: 52767, + NewRoot: utils.TestHexToFelt(t, "0x3d86be8765b9b6ab724fb8c10a64c4e1705bcc6d39032fe9973037abedc113a"), + Timestamp: 1661450764, + }, + Status: "ACCEPTED_ON_L1", + Transactions: []BlockTransaction{ + BlockInvokeTxnV3{ + TransactionHash: utils.TestHexToFelt(t, "0xb91eada292de46f4ec663bac57699c7b8f8fa454a8efad91fde7f35d941199"), + InvokeTxnV3: InvokeTxnV3{ + Type: "INVOKE", + SenderAddress: utils.TestHexToFelt(t, "0x573ea9a8602e03417a4a31d55d115748f37a08bbb23adf6347cb699743a998d"), + Nonce: utils.TestHexToFelt(t, "0x470de4df820000"), + Version: TransactionV3, + Signature: []*felt.Felt{ + utils.TestHexToFelt(t, "0x7f14bb280b602d0c0e22e91ea5d987371554664f68c57c0acd16bf9f8be36b4"), + utils.TestHexToFelt(t, "0x22c57ce8eb211c7fe0f04e7da338f579fcbc9e8997ec432fac7738c80fd56ad"), + }, + Calldata: []*felt.Felt{ + utils.TestHexToFelt(t, "0x1"), + utils.TestHexToFelt(t, "0x3fe8e4571772bbe0065e271686bd655efd1365a5d6858981e582f82f2c10313"), + utils.TestHexToFelt(t, "0x2468d193cd15b621b24c2a602b8dbcfa5eaa14f88416c40c09d7fd12592cb4b"), + utils.TestHexToFelt(t, "0x0"), + }, + ResourceBounds: ResourceBoundsMapping{ + L1Gas: ResourceBounds{ + MaxAmount: "0x3bb2", + MaxPricePerUnit: "0x2ba7def30000", + }, + L2Gas: ResourceBounds{ + MaxAmount: "0x0", + MaxPricePerUnit: "0x0", + }, + }, + Tip: "0x0", + PayMasterData: []*felt.Felt{}, + AccountDeploymentData: []*felt.Felt{}, + NonceDataMode: DAModeL1, + FeeMode: DAModeL1, + }, + }, + }, + } + + testSet := map[string][]testSetType{ + "mock": {}, + "testnet": { + { + BlockID: WithBlockTag("latest"), + ExpectedError: nil, + }, + { + BlockID: WithBlockHash(utils.TestHexToFelt(t, "0x4ae5d52c75e4dea5694f456069f830cfbc7bec70427eee170c3385f751b8564")), + ExpectedError: nil, + LookupTxnPositionInExpected: 0, + LookupTxnPositionInOriginal: 25, + want: &fullBlockSepolia52767, + }, + { + BlockID: WithBlockNumber(52767), + ExpectedError: nil, + LookupTxnPositionInExpected: 0, + LookupTxnPositionInOriginal: 25, + want: &fullBlockSepolia52767, + }, + }, + "mainnet": {}, + }[testEnv] + for _, test := range testSet { + spy := NewSpy(testConfig.provider.c) + testConfig.provider.c = spy + blockWithTxsInterface, err := testConfig.provider.BlockWithTxs(context.Background(), test.BlockID) + if err != test.ExpectedError { + t.Fatal("BlockWithTxHashes match the expected error:", err) + } + if test.ExpectedError != nil && blockWithTxsInterface == nil { + continue + } + blockWithTxs, ok := blockWithTxsInterface.(*Block) + if !ok { + t.Fatalf("expecting *rpv02.Block, instead %T", blockWithTxsInterface) + } + _, err = spy.Compare(blockWithTxs, false) + if err != nil { + t.Fatal("expecting to match", err) + } + if !strings.HasPrefix(blockWithTxs.BlockHash.String(), "0x") { + t.Fatal("Block Hash should start with \"0x\", instead", blockWithTxs.BlockHash) } + if len(blockWithTxs.Transactions) == 0 { + t.Fatal("the number of transaction should not be 0") + } + + if test.want != nil { + if (*test.want).BlockHash == &felt.Zero { + continue + } + + invokeV3Want, ok := (*test.want).Transactions[test.LookupTxnPositionInExpected].(BlockInvokeTxnV3) + if !ok { + t.Fatal("expected invoke v3 transaction") + } + + invokeV3Block, ok := blockWithTxs.Transactions[test.LookupTxnPositionInOriginal].(BlockInvokeTxnV3) + if !ok { + t.Fatal("expected invoke v3 transaction") + } + + require.Equal(t, invokeV3Want.TransactionHash, invokeV3Block.TransactionHash, "expected equal TransactionHash") + require.Equal(t, invokeV3Want.InvokeTxnV3.NonceDataMode, invokeV3Block.InvokeTxnV3.NonceDataMode, "expected equal nonceDataMode") + require.Equal(t, invokeV3Want.InvokeTxnV3.FeeMode, invokeV3Block.InvokeTxnV3.FeeMode, "expected equal feeMode") + } } } // TestBlockWithTxsAndDeployOrDeclare tests BlockWithTxs with Deploy or Declare TXN // TestBlockWithTxsAndDeployOrDeclare is a test function that tests the functionality of the BlockWithTxs function. -// It creates a test configuration, defines a testSetType struct, and initializes three Blocks (fullBlockGoerli310843, fullBlockGoerli848622 and fullBlockGoerli849399). +// It creates a test configuration, defines a testSetType struct, and initializes three Blocks (fullBlockSepolia52959, fullBlockSepolia848622 and fullBlockSepolia849399). // It then defines a testSet map with different test scenarios for the BlockWithTxs function. // The function iterates over the testSet and performs the BlockWithTxs operation on each test case. // It compares the returned blockWithTxs with the expected result and verifies the correctness of the operation. @@ -426,7 +683,7 @@ func TestBlockWithTxsAndInvokeTXNV0(t *testing.T) { // Returns: // // none -func TestBlockWithTxsAndDeployOrDeclare(t *testing.T) { +func TestBlockWithTxsAndDeployAccountOrDeclare(t *testing.T) { testConfig := beforeEach(t) type testSetType struct { @@ -437,83 +694,93 @@ func TestBlockWithTxsAndDeployOrDeclare(t *testing.T) { ExpectedBlockWithTxs *Block } - // TODO : re-add test for deploy account transaction - var fullBlockGoerli310843 = Block{ + var fullBlockSepolia52959 = Block{ BlockHeader: BlockHeader{ - BlockHash: utils.TestHexToFelt(t, "0x424fba26a7760b63895abe0c366c2d254cb47090c6f9e91ba2b3fa0824d4fc9"), - ParentHash: utils.TestHexToFelt(t, "0x30e34dedf00bb35a9076b2b0f50a5a74fd2501f62094b6e687277be6ef3d444"), - SequencerAddress: utils.TestHexToFelt(t, "0x46a89ae102987331d369645031b49c27738ed096f2789c24449966da4c6de6b"), - BlockNumber: 310843, - NewRoot: utils.TestHexToFelt(t, "0x32bd4ff21288c898d4d3b6a7aea4ebdb3f1c7089cd52bde98316b4ecb8a50be"), - Timestamp: 1661486036, + BlockHash: utils.TestHexToFelt(t, "0x5e4c92970bb2bc51a3824a8357078ef00e0c089313c4ac1d9004166d9adc6aa"), + ParentHash: utils.TestHexToFelt(t, "0x469f2b163bd62e042e77390ae3d1fa278212e279408163e14624d39d6529bd5"), + SequencerAddress: utils.TestHexToFelt(t, "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"), + BlockNumber: 52959, + NewRoot: utils.TestHexToFelt(t, "0x5aebb84ffae11caa645da6ade011df2e5d60a1943d9533fcd8326ff5ca000b2"), + Timestamp: 1711378335, }, Status: "ACCEPTED_ON_L1", Transactions: []BlockTransaction{ - BlockDeployTxn{ - TransactionHash: utils.TestHexToFelt(t, "0x35bd2978d2061b3463498f83c09322ed6a82e4b2a188506525e272a7adcdf6a"), - DeployTxn: DeployTxn{ - ClassHash: utils.TestHexToFelt(t, "0x1ca349f9721a2bf05012bb475b404313c497ca7d6d5f80c03e98ff31e9867f5"), + BlockDeployAccountTxn{ + TransactionHash: utils.TestHexToFelt(t, "0x38d17f7aaa320f43a638a0097a43332614d3306d91036cab258a07441a14a10"), + DeployAccountTxn: DeployAccountTxn{ + ClassHash: utils.TestHexToFelt(t, "0x29927c8af6bccf3f6fda035981e765a7bdbf18a2dc0d630494f8758aa908e2b"), + Signature: []*felt.Felt{ + utils.TestHexToFelt(t, "0x20b878ad13672908aadeb500348d3c172a9d2534474d5f87788de5268b29c4e"), + utils.TestHexToFelt(t, "0xd4b95c47f5234c220e2c9bc96b15677aad0cc47d74ed647c53ab121f632e95"), + }, ConstructorCalldata: []*felt.Felt{ - utils.TestHexToFelt(t, "0x31ad196615d50956d98be085eb1774624106a6936c7c38696e730d2a6df735a"), - utils.TestHexToFelt(t, "0x736affc32af71f8d361c855b38ffef58ec151bd8361a3b160017b90ada1068e"), + utils.TestHexToFelt(t, "0x7e02fa1096a3292b92f28167a180dc6b0944f1d0cc1b4919c88cc2ca961848"), + utils.TestHexToFelt(t, "0x0"), }, - ContractAddressSalt: utils.TestHexToFelt(t, "0x4241e90ee6a33a1e2e70b088f7e4acfb3d6630964c1a85e96fa96acd56dcfcf"), - - Type: "DEPLOY", - Version: TransactionV0, + ContractAddressSalt: utils.TestHexToFelt(t, "0x7e02fa1096a3292b92f28167a180dc6b0944f1d0cc1b4919c88cc2ca961848"), + MaxFee: utils.TestHexToFelt(t, "0x12aff9cd5fac"), + Type: "DEPLOY_ACCOUNT", + Nonce: utils.TestHexToFelt(t, "0x0"), + Version: TransactionV1, }, }, }, } - var fullBlockGoerli848622 = Block{ + var fullBlockSepolia53617 = Block{ BlockHeader: BlockHeader{ - BlockHash: utils.TestHexToFelt(t, "0x32964e2e407bb9e71b2de8d9d9829b0537df7c4624e1816e6cece80781ab9cc"), - ParentHash: utils.TestHexToFelt(t, "0xecbed6cfe85c77f2f8acefe2effbda817f71ca7457f7ece8262d65cc87a9f7"), + BlockHash: utils.TestHexToFelt(t, "0x526355d90ef6118d4f871ccdb3a3d0ea27d10b0a02b3005e7697dd321b52ada"), + ParentHash: utils.TestHexToFelt(t, "0x645b998412c408e979577b357f4afc0902652fed85bdd7f9d81b7fa2ffc9506"), SequencerAddress: utils.TestHexToFelt(t, "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"), - BlockNumber: 848622, - NewRoot: utils.TestHexToFelt(t, "07c4302f09f6a72129679378e9b8d6c67774c5c4e80b1fc186da114f71637b2e"), - Timestamp: 1692416283, + BlockNumber: 53617, + NewRoot: utils.TestHexToFelt(t, "0x703f5a9be28fc4e57f3dd84abd05acb5bbdc957b77ce9e134b0d5d08d04d9ec"), + Timestamp: 1711538993, }, Status: "ACCEPTED_ON_L1", Transactions: []BlockTransaction{ BlockDeclareTxnV1{ - TransactionHash: utils.TestHexToFelt(t, "0x5ad2f85499ea92d33d4a44c8cd4640d1ee4e25c3ee6df0bdf0a76c12c052f0a"), + TransactionHash: utils.TestHexToFelt(t, "0x7ff4942928fb6383514fd18d8b4ddc8a154b496d2204f60ee47e6272305172c"), DeclareTxnV1: DeclareTxnV1{ - Type: TransactionType_Declare, - MaxFee: utils.TestHexToFelt(t, "0x27a64c6e425"), - Version: TransactionV1, - Signature: []*felt.Felt{utils.TestHexToFelt(t, "0x1454ab28f0bf18f0fd8002bc92169e6443feba6c605728c86850c0dcc9f6f9a"), utils.TestHexToFelt(t, "0xf545949c899ff1d16c61629996e898db2697a2e3e7fa9071b016500ca5c1d1")}, - Nonce: utils.TestHexToFelt(t, "0x333"), - ClassHash: utils.TestHexToFelt(t, "0x681076f783aa2b3faec6ce80bb5485a260ed1672007925e1d502b003aff2232"), - SenderAddress: utils.TestHexToFelt(t, "0x45dba6ce6a4dc3d2f31aa6da5f51007f1e43e84a1e62c4481bac5454dea4e6d"), + Type: TransactionType_Declare, + MaxFee: utils.TestHexToFelt(t, "0x3365d77ce5000"), + Version: TransactionV1, + Signature: []*felt.Felt{ + utils.TestHexToFelt(t, "0x106b85d29dfe14af94d46e8758491c468f0812227c8969de7f7c382355bd72c"), + utils.TestHexToFelt(t, "0x28a8bdedf588daa657057240e952fb93070290b6d906bc80c9e9e3f3e3be6da"), + }, + Nonce: utils.TestHexToFelt(t, "0x128"), + ClassHash: utils.TestHexToFelt(t, "0x6b433af0dff031b3578de26217fa7cd2a8ac0d70c25f8fbf332fc603a5dcf2d"), + SenderAddress: utils.TestHexToFelt(t, "0x2cc631ca0c544639f6e4403b8f3611696a3d831e8157ea1c946e35429c7ac31"), }, }, }, } - var fullBlockGoerli849399 = Block{ + var fullBlockSepolia53794 = Block{ BlockHeader: BlockHeader{ - BlockHash: utils.TestHexToFelt(t, "0x6e5b26127400bac0cd1f3c2ab6e76850ec457c71b1f2fc7cda755bee8a1102a"), - ParentHash: utils.TestHexToFelt(t, "0x7cd085d4ab95b3307303cb836ab49c0fbc8d1f9befdcfdc65292d99c9466d05"), + BlockHash: utils.TestHexToFelt(t, "0x5d216dd9e394a088330b5d77a4a282618b7f0796a2ef8f081c5aa01e3ace6f0"), + ParentHash: utils.TestHexToFelt(t, "0x6e31bf89281805f949a0ab5d7bf6fa44becf7c4cff4d426626a1647376e461f"), SequencerAddress: utils.TestHexToFelt(t, "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"), - BlockNumber: 849399, - NewRoot: utils.TestHexToFelt(t, "0x239a44410e78665f41f7a65ef3b5ed244ce411965498a83f80f904e22df1045"), - Timestamp: 1692560305, + BlockNumber: 53794, + NewRoot: utils.TestHexToFelt(t, "0x1c6f8a85528d03dcf88a4087bb191bd608f301a7eb3e05d236b0c441fc30174"), + Timestamp: 1711582037, }, Status: "ACCEPTED_ON_L1", Transactions: []BlockTransaction{ BlockDeclareTxnV2{ - TransactionHash: utils.TestHexToFelt(t, "0x45d04652ba51685b7b82fc17b3d5741a7c43992369c0b0aebd60916fa23b9b2"), + TransactionHash: utils.TestHexToFelt(t, "0x7c0108477e9ece3dbd421f74e73bd4e15c7fcb496784e99d4b6f6710463b6f3"), DeclareTxnV2: DeclareTxnV2{ - Type: TransactionType_Declare, - MaxFee: utils.TestHexToFelt(t, "0x50c8f30287c"), - Version: TransactionV2, - Signature: []*felt.Felt{utils.TestHexToFelt(t, "0x6be01a56087382337a29fd4577dd20fd82cc9f38f69b8d19e07fc101c3c5ad9"), utils.TestHexToFelt(t, "0x4c633a5582d3932fbfcea8abd45c7453e88a562f1a38877b9575d6a6b926ea2")}, - Nonce: utils.TestHexToFelt(t, "0xd"), - ClassHash: utils.TestHexToFelt(t, "0x6fda8f6630f44571cd6b398795351b37daf27adacbf6fe9357bd23ad19b22f3"), - CompiledClassHash: utils.TestHexToFelt(t, "0x4380d7c6511f81668530570a8b07bd2148808f90e681bb769549ec4faafef65"), - SenderAddress: utils.TestHexToFelt(t, "0x6ef69146f56205e27624a9933f31d6009198c1ea480070a790f16a5d928be92"), + Type: TransactionType_Declare, + MaxFee: utils.TestHexToFelt(t, "0xde0b6b3a7640000"), + Version: TransactionV2, + Signature: []*felt.Felt{ + utils.TestHexToFelt(t, "0x2dd7cf8724045aa56edce10f96d1ec62a89492dc69e43d4b21c62a3708f3eb6"), + utils.TestHexToFelt(t, "0x4918acc659aa5e4e4b4b8a7ffdc3686fefd219c556ef7582904675cae6b1028"), + }, + Nonce: utils.TestHexToFelt(t, "0x353"), + ClassHash: utils.TestHexToFelt(t, "0x36f7463a30a3ff34ecdcfeea4aa880b97c366523925b1ba069faadddbef0e02"), + CompiledClassHash: utils.TestHexToFelt(t, "0x5047109bf7eb550c5e6b0c37714f6e0db4bb8b5b227869e0797ecfc39240aa7"), + SenderAddress: utils.TestHexToFelt(t, "0xaf46a3d75c1abc204cbe7e08f220680958bd8aca2c3cfc2ef34c686148ecf7"), }, }, }, @@ -527,46 +794,46 @@ func TestBlockWithTxsAndDeployOrDeclare(t *testing.T) { ExpectedError: nil, }, { - BlockID: WithBlockHash(utils.TestHexToFelt(t, "0x424fba26a7760b63895abe0c366c2d254cb47090c6f9e91ba2b3fa0824d4fc9")), + BlockID: WithBlockHash(utils.TestHexToFelt(t, "0x5e4c92970bb2bc51a3824a8357078ef00e0c089313c4ac1d9004166d9adc6aa")), ExpectedError: nil, - LookupTxnPositionInOriginal: 14, + LookupTxnPositionInOriginal: 4, LookupTxnPositionInExpected: 0, - ExpectedBlockWithTxs: &fullBlockGoerli310843, + ExpectedBlockWithTxs: &fullBlockSepolia52959, }, { - BlockID: WithBlockNumber(310843), + BlockID: WithBlockNumber(52959), ExpectedError: nil, - LookupTxnPositionInOriginal: 14, + LookupTxnPositionInOriginal: 4, LookupTxnPositionInExpected: 0, - ExpectedBlockWithTxs: &fullBlockGoerli310843, + ExpectedBlockWithTxs: &fullBlockSepolia52959, }, { - BlockID: WithBlockNumber(849399), + BlockID: WithBlockHash(utils.TestHexToFelt(t, "0x5d216dd9e394a088330b5d77a4a282618b7f0796a2ef8f081c5aa01e3ace6f0")), ExpectedError: nil, - LookupTxnPositionInOriginal: 71, + LookupTxnPositionInOriginal: 72, LookupTxnPositionInExpected: 0, - ExpectedBlockWithTxs: &fullBlockGoerli849399, + ExpectedBlockWithTxs: &fullBlockSepolia53794, }, { - BlockID: WithBlockNumber(848622), + BlockID: WithBlockNumber(53794), ExpectedError: nil, - LookupTxnPositionInOriginal: 6, + LookupTxnPositionInOriginal: 72, LookupTxnPositionInExpected: 0, - ExpectedBlockWithTxs: &fullBlockGoerli848622, + ExpectedBlockWithTxs: &fullBlockSepolia53794, }, { - BlockID: WithBlockNumber(849399), + BlockID: WithBlockHash(utils.TestHexToFelt(t, "0x526355d90ef6118d4f871ccdb3a3d0ea27d10b0a02b3005e7697dd321b52ada")), ExpectedError: nil, - LookupTxnPositionInOriginal: 71, + LookupTxnPositionInOriginal: 72, LookupTxnPositionInExpected: 0, - ExpectedBlockWithTxs: &fullBlockGoerli849399, + ExpectedBlockWithTxs: &fullBlockSepolia53617, }, { - BlockID: WithBlockNumber(848622), + BlockID: WithBlockNumber(53617), ExpectedError: nil, - LookupTxnPositionInOriginal: 6, + LookupTxnPositionInOriginal: 72, LookupTxnPositionInExpected: 0, - ExpectedBlockWithTxs: &fullBlockGoerli848622, + ExpectedBlockWithTxs: &fullBlockSepolia53617, }, }, "mainnet": {}, @@ -645,8 +912,8 @@ func TestBlockTransactionCount(t *testing.T) { }, "testnet": { { - BlockID: WithBlockNumber(300000), - ExpectedCount: 23, + BlockID: WithBlockNumber(52959), + ExpectedCount: 58, }, }, "mainnet": {}, @@ -692,8 +959,8 @@ func TestCaptureUnsupportedBlockTxn(t *testing.T) { "mock": {}, "testnet": { { - StartBlock: 381000, - EndBlock: 381001, + StartBlock: 52959, + EndBlock: 52960, }, }, "mainnet": {}, @@ -709,15 +976,17 @@ func TestCaptureUnsupportedBlockTxn(t *testing.T) { t.Fatalf("expecting *rpc.Block, instead %T", blockWithTxsInterface) } for k, v := range blockWithTxs.Transactions { - _, okv1 := v.(BlockInvokeTxnV1) _, okv0 := v.(BlockInvokeTxnV0) + _, okv1 := v.(BlockInvokeTxnV1) + _, okv3 := v.(BlockInvokeTxnV3) _, okl1 := v.(BlockL1HandlerTxn) _, okdec0 := v.(BlockDeclareTxnV0) _, okdec1 := v.(BlockDeclareTxnV1) _, okdec2 := v.(BlockDeclareTxnV2) + _, okdec3 := v.(BlockDeclareTxnV3) _, okdep := v.(BlockDeployTxn) _, okdepac := v.(BlockDeployAccountTxn) - if !okv0 && !okv1 && !okl1 && !okdec0 && !okdec1 && !okdec2 && !okdep && !okdepac { + if !okv0 && !okv1 && !okv3 && !okl1 && !okdec0 && !okdec1 && !okdec2 && !okdec3 && !okdep && !okdepac { t.Fatalf("New Type Detected %T at Block(%d)/Txn(%d)", v, i, k) } } @@ -725,37 +994,6 @@ func TestCaptureUnsupportedBlockTxn(t *testing.T) { } } -// TestBlockWithTxsAndInvokeTXNV1 is a test function that tests the behavior of the BlockWithTxsAndInvokeTXNV1 function. -// -// Parameters: -// - t: the testing object for running the test cases -// Returns: -// -// none -// -// TODO: Find a block with such a Txn -func TestBlockWithTxsAndInvokeTXNV1(t *testing.T) { - _ = beforeEach(t) - - type testSetType struct { - check bool - } - testSet := map[string][]testSetType{ - "mock": {}, - "testnet": { - { - check: false, - }, - }, - "mainnet": {}, - }[testEnv] - for _, test := range testSet { - if test.check { - t.Fatalf("error running test: %v", ErrNotImplemented) - } - } -} - // TestStateUpdate is a test function for the StateUpdate method. // // It tests the StateUpdate method by creating a test set and iterating through each test case. @@ -763,9 +1001,6 @@ func TestBlockWithTxsAndInvokeTXNV1(t *testing.T) { // Then, it calls the StateUpdate method with the given test block ID. // If there is an error, it fails the test. // If the returned block hash does not match the expected block hash, it fails the test. -// TODO: this is not implemented yet with pathfinder as you can see from the -// [code](https://github.com/eqlabs/pathfinder/blob/927183552dad6dcdfebac16c8c1d2baf019127b1/crates/pathfinder/rpc_examples.sh#L37) -// check when it is and test when it is the case. // // Parameters: // - t: the testing object for running the test cases @@ -806,19 +1041,45 @@ func TestStateUpdate(t *testing.T) { }, "testnet": { { - BlockID: WithBlockNumber(300000), + BlockID: WithBlockNumber(52767), ExpectedStateUpdateOutput: StateUpdateOutput{ - BlockHash: utils.TestHexToFelt(t, "0x03b6d94b246815960f38b7dffc53cda192e7d1dcfff61e1bc042fb57e95f8349"), - NewRoot: utils.TestHexToFelt(t, "0x70677cda9269d47da3ff63bc87cf1c87d0ce167b05da295dc7fc68242b250b"), + BlockHash: utils.TestHexToFelt(t, "0x4ae5d52c75e4dea5694f456069f830cfbc7bec70427eee170c3385f751b8564"), + NewRoot: utils.TestHexToFelt(t, "0x3d86be8765b9b6ab724fb8c10a64c4e1705bcc6d39032fe9973037abedc113a"), PendingStateUpdate: PendingStateUpdate{ - OldRoot: utils.TestHexToFelt(t, "0x19aa982a75263d4c4de4cc4c5d75c3dec32e00b95bef7bbb4d17762a0b138af"), + OldRoot: utils.TestHexToFelt(t, "0x53798359cae2b3c7f11afdf82d115f57699200452f0f8f0f7fbc272792e363c"), StateDiff: StateDiff{ + DeclaredClasses: []DeclaredClassesItem{}, + DeprecatedDeclaredClasses: []*felt.Felt{}, + ReplacedClasses: []ReplacedClassesItem{}, + DeployedContracts: []DeployedContractItem{ + { + Address: utils.TestHexToFelt(t, "0x6c48aac405091db3c23cafd25766a59aa41280ecc28c8c65f060a1db3c55c4d"), + ClassHash: utils.TestHexToFelt(t, "0x11cc8ea386ce27c8308bb0bb87e84ef9e3b83d6a86dda980f9efe275c4f45e6"), + }, + }, + Nonces: []ContractNonce{ + { + ContractAddress: utils.TestHexToFelt(t, "0x23a4d7f2cdf202ea916bbb07814f5bc32ae50e9cdf1fde114d8e6e808b1e965"), + Nonce: utils.TestHexToFelt(t, "0x2dc7"), + }, + }, StorageDiffs: []ContractStorageDiffItem{{ - Address: utils.TestHexToFelt(t, "0xe5cc6f2b6d34979184b88334eb64173fe4300cab46ecd3229633fcc45c83d4"), + // Address: utils.TestHexToFelt(t, "0x710851e5f08a67ef2f7ea6814bfa4dc8976505c20e05519d7694d2c3aca433b"), + // StorageEntries: []StorageEntry{ + // { + // Key: utils.TestHexToFelt(t, "0x75eced5eac353d176ff0873f7742d97dd0ca449ce865ef19eaf5be4a057761c"), + // Value: utils.TestHexToFelt(t, "0x45e64583ec6d31caeb064865366b9742687a0c7892219ed0596b00928257ef"), + // }, + // { + // Key: utils.TestHexToFelt(t, "0x75eced5eac353d176ff0873f7742d97dd0ca449ce865ef19eaf5be4a057761b"), + // Value: utils.TestHexToFelt(t, "0x129b9752d317c583dd5ad8578d8be879eab2b2f5a4b4e70f80fbcdf653c418d"), + // }, + // }, + Address: utils.TestHexToFelt(t, "0x1"), StorageEntries: []StorageEntry{ { - Key: utils.TestHexToFelt(t, "0x1813aac5f5e7799684c6dc33e51f44d3627fd748c800724a184ed5be09b713e"), - Value: utils.TestHexToFelt(t, "0x630b4197"), + Key: utils.TestHexToFelt(t, "0xce15"), + Value: utils.TestHexToFelt(t, "0x399c6ae71bb87c1cef573f98d14530f39f2b40fc95b2396f379930969700895"), }, }, }}, @@ -836,8 +1097,11 @@ func TestStateUpdate(t *testing.T) { if err != nil { t.Fatal(err) } - if stateUpdate.BlockHash.String() != test.ExpectedStateUpdateOutput.BlockHash.String() { - t.Fatalf("structure expecting %s, instead: %s", test.ExpectedStateUpdateOutput.BlockHash.String(), stateUpdate.BlockHash.String()) - } + require.Equal(t, test.ExpectedStateUpdateOutput.BlockHash, stateUpdate.BlockHash, "expected equal BlockHash") + require.Equal(t, test.ExpectedStateUpdateOutput.OldRoot, stateUpdate.OldRoot, "expected equal OldRoot") + require.Equal(t, test.ExpectedStateUpdateOutput.NewRoot, stateUpdate.NewRoot, "expected equal NewRoot") + require.Equal(t, test.ExpectedStateUpdateOutput.StateDiff.DeployedContracts, stateUpdate.StateDiff.DeployedContracts, "expected equal DeployedContracts") + require.Contains(t, stateUpdate.StateDiff.Nonces, test.ExpectedStateUpdateOutput.StateDiff.Nonces[0], "expected equal Nonces") + require.Contains(t, stateUpdate.StateDiff.StorageDiffs, test.ExpectedStateUpdateOutput.StateDiff.StorageDiffs[0], "expected equal StorageDiffs") } } diff --git a/rpc/types_block_transaction.go b/rpc/types_block_transaction.go index df08bd07..68a73eef 100644 --- a/rpc/types_block_transaction.go +++ b/rpc/types_block_transaction.go @@ -16,9 +16,11 @@ type BlockTransaction interface { var _ BlockTransaction = BlockInvokeTxnV0{} var _ BlockTransaction = BlockInvokeTxnV1{} +var _ BlockTransaction = BlockInvokeTxnV3{} var _ BlockTransaction = BlockDeclareTxnV0{} var _ BlockTransaction = BlockDeclareTxnV1{} var _ BlockTransaction = BlockDeclareTxnV2{} +var _ BlockTransaction = BlockDeclareTxnV3{} var _ BlockTransaction = BlockDeployTxn{} var _ BlockTransaction = BlockDeployAccountTxn{} var _ BlockTransaction = BlockL1HandlerTxn{} @@ -47,6 +49,18 @@ func (tx BlockInvokeTxnV1) Hash() *felt.Felt { return tx.TransactionHash } +// Hash returns the hash of the BlockInvokeTxnV3 transaction. +// +// Parameters: +// +// none +// +// Returns: +// - *felt.Felt: the transaction hash +func (tx BlockInvokeTxnV3) Hash() *felt.Felt { + return tx.TransactionHash +} + // Hash returns the transaction hash of the BlockDeclareTxnV0. // // Parameters: @@ -83,6 +97,18 @@ func (tx BlockDeclareTxnV2) Hash() *felt.Felt { return tx.TransactionHash } +// Hash returns the transaction hash of the BlockDeclareTxnV3. +// +// Parameters: +// +// none +// +// Returns: +// - *felt.Felt: the transaction hash +func (tx BlockDeclareTxnV3) Hash() *felt.Felt { + return tx.TransactionHash +} + // Hash returns the hash of the BlockDeployTxn. // // Parameters: @@ -129,6 +155,11 @@ type BlockInvokeTxnV1 struct { InvokeTxnV1 } +type BlockInvokeTxnV3 struct { + TransactionHash *felt.Felt `json:"transaction_hash"` + InvokeTxnV3 +} + type BlockL1HandlerTxn struct { TransactionHash *felt.Felt `json:"transaction_hash"` L1HandlerTxn @@ -149,6 +180,11 @@ type BlockDeclareTxnV2 struct { DeclareTxnV2 } +type BlockDeclareTxnV3 struct { + TransactionHash *felt.Felt `json:"transaction_hash"` + DeclareTxnV3 +} + type BlockDeployTxn struct { TransactionHash *felt.Felt `json:"transaction_hash"` DeployTxn @@ -213,8 +249,12 @@ func unmarshalBlockTxn(t interface{}) (BlockTransaction, error) { var txn BlockDeclareTxnV2 err := remarshal(casted, &txn) return txn, err + case "0x3": + var txn BlockDeclareTxnV3 + err := remarshal(casted, &txn) + return txn, err default: - return nil, errors.New("Internal error with Declare transaction version and unmarshalTxn()") + return nil, errors.New("internal error with Declare transaction version and unmarshalTxn()") } case TransactionType_Deploy: var txn BlockDeployTxn @@ -227,12 +267,16 @@ func unmarshalBlockTxn(t interface{}) (BlockTransaction, error) { case TransactionType_Invoke: if casted["version"].(string) == "0x0" { var txn BlockInvokeTxnV0 - err := remarshal(casted, &txn) - return txn, err - } else { + remarshal(casted, &txn) + return txn, nil + } else if casted["version"].(string) == "0x1" { var txn BlockInvokeTxnV1 - err := remarshal(casted, &txn) - return txn, err + remarshal(casted, &txn) + return txn, nil + } else { + var txn BlockInvokeTxnV3 + remarshal(casted, &txn) + return txn, nil } case TransactionType_L1Handler: var txn BlockL1HandlerTxn diff --git a/rpc/types_transaction.go b/rpc/types_transaction.go index 624d911e..9df18f84 100644 --- a/rpc/types_transaction.go +++ b/rpc/types_transaction.go @@ -156,7 +156,7 @@ func (da *DataAvailabilityMode) UInt64() (uint64, error) { case DAModeL2: return uint64(1), nil } - return 0, errors.New("Unknown DAMode") + return 0, errors.New("unknown DAMode") } type Resource string