From 177f00e963e778a8bdc7ef87632f7688c3a98095 Mon Sep 17 00:00:00 2001 From: Thiago Ribeiro <62709592+thiagodeev@users.noreply.github.com> Date: Wed, 8 May 2024 11:09:28 -0300 Subject: [PATCH 1/3] provider_test.go upgraded to Sepolia (#563) * use rust devnet --- .github/workflows/main_ci_check.yml | 2 +- .github/workflows/test.yml | 2 +- .github/workflows/test_account.yml | 2 +- .github/workflows/test_rpc.yml | 2 +- devnet/devnet.go | 20 ++++++++++----- devnet/devnet_test.go | 38 +++++++++-------------------- rpc/call_test.go | 6 ++--- rpc/mock_test.go | 4 +-- rpc/provider_test.go | 16 ++++++------ 9 files changed, 43 insertions(+), 49 deletions(-) diff --git a/.github/workflows/main_ci_check.yml b/.github/workflows/main_ci_check.yml index 7370b125..053723a1 100644 --- a/.github/workflows/main_ci_check.yml +++ b/.github/workflows/main_ci_check.yml @@ -11,7 +11,7 @@ jobs: services: devnet: - image: shardlabs/starknet-devnet:latest + image: shardlabs/starknet-devnet-rs:0.0.5 ports: - 5050:5050 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2527caad..549139c4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,7 @@ jobs: services: devnet: - image: shardlabs/starknet-devnet:0.3.4 + image: shardlabs/starknet-devnet-rs:0.0.5 ports: - 5050:5050 diff --git a/.github/workflows/test_account.yml b/.github/workflows/test_account.yml index ec6784e3..016da641 100644 --- a/.github/workflows/test_account.yml +++ b/.github/workflows/test_account.yml @@ -13,7 +13,7 @@ jobs: services: devnet: - image: shardlabs/starknet-devnet:0.5.5 + image: shardlabs/starknet-devnet-rs:0.0.5 ports: - 5050:5050 diff --git a/.github/workflows/test_rpc.yml b/.github/workflows/test_rpc.yml index 4a5b26b5..7d8691b9 100644 --- a/.github/workflows/test_rpc.yml +++ b/.github/workflows/test_rpc.yml @@ -13,7 +13,7 @@ jobs: services: devnet: - image: shardlabs/starknet-devnet:latest + image: shardlabs/starknet-devnet-rs:0.0.5 ports: - 5050:5050 diff --git a/devnet/devnet.go b/devnet/devnet.go index f06f4d48..64f44e7e 100644 --- a/devnet/devnet.go +++ b/devnet/devnet.go @@ -60,7 +60,9 @@ func (devnet *DevNet) api(uri string) string { // the list of accounts and any error that occurred during the process. // // Parameters: -// none +// +// none +// // Returns: // - []TestAccount: a slice of TestAccount structs func (devnet *DevNet) Accounts() ([]TestAccount, error) { @@ -87,9 +89,12 @@ func (devnet *DevNet) Accounts() ([]TestAccount, error) { // and false otherwise. // // Parameters: -// none +// +// none +// // Returns: -// bool: true if the DevNet is alive, false otherwise +// +// bool: true if the DevNet is alive, false otherwise func (devnet *DevNet) IsAlive() bool { req, err := http.NewRequest(http.MethodGet, devnet.api("/is_alive"), nil) if err != nil { @@ -107,8 +112,9 @@ func (devnet *DevNet) IsAlive() bool { } type MintResponse struct { - NewBalance *big.Int `json:"new_balance"` - Unit string `json:"unit"` + NewBalance string `json:"new_balance"` + Unit string `json:"unit"` + TransactionHash string `json:"tx_hash"` } // Mint mints a certain amount of tokens for a given address. @@ -160,7 +166,9 @@ type FeeToken struct { // to retrieve the fee token. // // Parameters: -// none +// +// none +// // Returns: // - *FeeToken: a pointer to a FeeToken object // - error: an error, if any diff --git a/devnet/devnet_test.go b/devnet/devnet_test.go index a76e9d83..698dd941 100644 --- a/devnet/devnet_test.go +++ b/devnet/devnet_test.go @@ -2,6 +2,7 @@ package devnet import ( "math/big" + "strconv" "strings" "testing" @@ -16,7 +17,8 @@ import ( // Parameters: // - t: is the testing.T instance for running the test // Returns: -// none +// +// none func TestDevnet_IsAlive(t *testing.T) { d := NewDevNet() if !d.IsAlive() { @@ -30,9 +32,11 @@ func TestDevnet_IsAlive(t *testing.T) { // account addresses are valid. // // Parameters: -// - t: is the testing.T instance for running the test +// - t: is the testing.T instance for running the test +// // Returns: -// none +// +// none func TestDevnet_Accounts(t *testing.T) { d := NewDevNet() accounts, err := d.Accounts() @@ -44,26 +48,6 @@ func TestDevnet_Accounts(t *testing.T) { } } -// TestDevnet_FeeToken tests the FeeToken function of the Devnet struct. -// -// The function retrieves the fee token from the Devnet instance and checks that -// it matches the expected ETH address. -// -// Parameters: -// - t: is the testing.T instance for running the test -// Returns: -// none -func TestDevnet_FeeToken(t *testing.T) { - d := NewDevNet() - token, err := d.FeeToken() - if err != nil { - t.Fatalf("Reading token should succeed, instead: %v", err) - } - if token.Address.String() != DevNetETHAddress { - t.Fatalf("devnet ETH address, instead %s", token.Address.String()) - } -} - // TestDevnet_Mint is a test function that tests the Mint method of the Devnet struct. // // It initializes a new Devnet instance and sets the amount to 1000000000000000000. @@ -74,7 +58,8 @@ func TestDevnet_FeeToken(t *testing.T) { // Parameters: // - t: is the testing.T instance for running the test // Returns: -// none +// +// none func TestDevnet_Mint(t *testing.T) { d := NewDevNet() amount := big.NewInt(int64(1000000000000000000)) @@ -82,7 +67,8 @@ func TestDevnet_Mint(t *testing.T) { if err != nil { t.Fatalf("Minting ETH should succeed, instead: %v", err) } - if resp.NewBalance.Cmp(amount) < 0 { - t.Fatalf("ETH should be higher than the last mint, instead: %d", resp.NewBalance) + balance, _ := (strconv.ParseInt(resp.NewBalance, 10, 64)) + if balance < 0 { + t.Fatalf("ETH should be higher than the last mint, instead: %d", balance) } } diff --git a/rpc/call_test.go b/rpc/call_test.go index a5fd7c62..4b28f928 100644 --- a/rpc/call_test.go +++ b/rpc/call_test.go @@ -38,12 +38,12 @@ func TestCall(t *testing.T) { { FunctionCall: FunctionCall{ // ContractAddress of predeployed devnet Feetoken - ContractAddress: utils.TestHexToFelt(t, "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"), - EntryPointSelector: utils.GetSelectorFromNameFelt("name"), + ContractAddress: utils.TestHexToFelt(t, DevNetETHAddress), + EntryPointSelector: utils.GetSelectorFromNameFelt("decimals"), Calldata: []*felt.Felt{}, }, BlockID: WithBlockTag("latest"), - ExpectedPatternResult: utils.TestHexToFelt(t, "0x6574686572"), + ExpectedPatternResult: utils.TestHexToFelt(t, "0x12"), }, }, "mock": { diff --git a/rpc/mock_test.go b/rpc/mock_test.go index 2486aced..765da088 100644 --- a/rpc/mock_test.go +++ b/rpc/mock_test.go @@ -133,7 +133,7 @@ func mock_starknet_chainId(result interface{}, method string, args ...interface{ if len(args) != 0 { return errWrongArgs } - value := "0x534e5f474f45524c49" + value := "0x534e5f5345504f4c4941" *r = value return nil } @@ -533,7 +533,7 @@ func mock_starknet_getEvents(result interface{}, method string, args ...interfac events := EventChunk{ Events: []EmittedEvent{ - EmittedEvent{ + { BlockHash: blockHash, BlockNumber: 1472, TransactionHash: txHash, diff --git a/rpc/provider_test.go b/rpc/provider_test.go index 56aca78b..661d8bea 100644 --- a/rpc/provider_test.go +++ b/rpc/provider_test.go @@ -20,7 +20,7 @@ import ( const ( TestPublicKey = "0x783318b2cc1067e5c06d374d2bb9a0382c39aabd009b165d7a268b882971d6" - DevNetETHAddress = "0x62230ea046a9a5fbc261ac77d03c8d41e5d442db2284587570ab46455fd2488" + DevNetETHAddress = "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7" TestNetETHAddress = "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7" DevNetAccount032Address = "0x06bb9425718d801fd06f144abb82eced725f0e81db61d2f9f4c9a26ece46a829" TestNetAccount032Address = "0x6ca4fdd437dffde5253ba7021ef7265c88b07789aa642eafda37791626edf00" @@ -101,7 +101,7 @@ func beforeEach(t *testing.T) *testConfiguration { return &testConfig } - testConfig.base = "https://starknet-goerli.cartridge.gg" + testConfig.base = "https://free-rpc.nethermind.io/sepolia-juno" base := os.Getenv("INTEGRATION_BASE") if base != "" { testConfig.base = base @@ -137,10 +137,10 @@ func TestChainID(t *testing.T) { ChainID string } testSet := map[string][]testSetType{ - "devnet": {{ChainID: "SN_GOERLI"}}, + "devnet": {{ChainID: "SN_SEPOLIA"}}, "mainnet": {{ChainID: "SN_MAIN"}}, - "mock": {{ChainID: "SN_GOERLI"}}, - "testnet": {{ChainID: "SN_GOERLI"}}, + "mock": {{ChainID: "SN_SEPOLIA"}}, + "testnet": {{ChainID: "SN_SEPOLIA"}}, }[testEnv] for _, test := range testSet { @@ -186,7 +186,7 @@ func TestSyncing(t *testing.T) { "devnet": {}, "mainnet": {{ChainID: "SN_MAIN"}}, "mock": {{ChainID: "MOCK"}}, - "testnet": {{ChainID: "SN_GOERLI"}}, + "testnet": {{ChainID: "SN_SEPOLIA"}}, }[testEnv] for range testSet { @@ -305,9 +305,9 @@ func TestCookieManagement(t *testing.T) { resp, err = client.ChainID(context.Background()) require.Nil(t, err) - require.Equal(t, resp, "SN_GOERLI") + require.Equal(t, resp, "SN_SEPOLIA") resp, err = client.ChainID(context.Background()) require.Nil(t, err) - require.Equal(t, resp, "SN_GOERLI") + require.Equal(t, resp, "SN_SEPOLIA") } From dca89da2fdbba1d3cd4e38d534c05dba37f1464e Mon Sep 17 00:00:00 2001 From: Thiago Ribeiro <62709592+thiagodeev@users.noreply.github.com> Date: Tue, 14 May 2024 10:20:30 -0300 Subject: [PATCH 2/3] RPC/block tests upgraded to sepolia, fixed not running correct RPC url passed from env flag on CLI bug (#566) * update block_test.go to use Sepolia instead of goerli --- rpc/block_test.go | 504 +++++++++++++++++++++++++++---------------- rpc/mock_test.go | 4 +- rpc/provider_test.go | 5 +- 3 files changed, 323 insertions(+), 190 deletions(-) diff --git a/rpc/block_test.go b/rpc/block_test.go index e1fd247d..13838685 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 blockSepolia64159 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,44 @@ func TestBlockWithTxHashes(t *testing.T) { ExpectedPendingBlockWithTxHashes *PendingBlockTxHashes } - var blockGoerli310370 = BlockTxHashes{ + var blockSepolia64159 = 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, "0x6df565874b2ea6a02d346a23f9efb0b26abbf5708b51bb12587f88a49052964"), + ParentHash: utils.TestHexToFelt(t, "0x1406ec9385293905d6c20e9c5aa0bbf9f63f87d39cf12fcdfef3ed0d056c0f5"), + SequencerAddress: utils.TestHexToFelt(t, "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"), + BlockNumber: 64159, + NewRoot: utils.TestHexToFelt(t, "0x310be818a18de0d6f6c1391f467d0dbd1a2753e6dde876449448465f8e617f0"), + Timestamp: 1714901729, }, 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", + "0x5e3fcf2f7dc0f3786a7406dc271cc54a00ba4658f9d0567b25b8e2a90a6250f", + "0x603fec12cfbc73bcf411fdf6f7780d4698c71b989002192a1277025235b23b9", + "0x23a24d95872d0eb15bf54cfb432830a3b85ad5c621b5edf849f131a2a45988d", + "0x4a35d133717f1f0288346432037d7964a16e503100fdab4cc3914a44790f3b4", + "0x5f14364b746abcfdfc0280877ff6d18c311d363e62264d7f218c5da2d396acc", + "0x7b49053e9a0bcd28c40d946702c28cf4ba068ff2e1755eff3fd99d62aada1a8", + "0x173c7a20046ab576667a2581cdea9565160a76e028864102a4d0828ca35a0d3", + "0x5754961d70d6f39d0e2c71a1a4ff5df0a26b1ceda4881ca82898994379e1e73", + "0x402f81ce59e3e79ca12c9cffea888c3f02542f2f4926731cb2145a3b8e810d5", + "0x48fa3e27b725e595e910548f3c0bb1ddfb30d32b31ebbf23fa1e63a66b0e59d", + "0x3d43ca0ea28f8e412b6abb37b76e75ac33e7df177cc8e4221e361ed0621bcdd", + "0x692381bba0e8505a8e0b92d0f046c8272de9e65f050850df678a0c10d8781d", + "0x7a56162702394b43b8fc05c511e1ddbe490749f2fd6786365d5d59797cd2012", + "0xcaead659d470ac0b572f0a4d8831275d51944d08961aab1a85bd68f9e98409", + "0x73376f10049aa689a5c6bf78b39b5a8c76ce5fb6611290b3080aa0d4f492d56", + "0x45061dccdb8cb32e428ec7b25136ae3a691f02bf5d01bd2d30ae9d2d4a29d4e", + "0x707071e6d5354a254935bf605b4eba4bb289261dc9ce75c1e9d8ad1367a5154", + "0x5358c68fa172aafabae1a007f5ec71eb1bddd64d4574366880f253287e8a0be", + "0x27a2e57d2ead1f9b7ce99c2e7b367820ecedf66cae3353572e6e7a7de89d1ce", + "0x59866d2230404c1c5787b523d3233f7f9d4ea9faf804ff747a0a2d3da77720e", + "0x5d41f4dec3678156d3888d6b890648c3baa02d866820689d5f8b3e20735521b", }), } txHashes := utils.TestHexArrToFelt(t, []string{ - "0x40c82f79dd2bc1953fc9b347a3e7ab40fe218ed5740bf4e120f74e8a3c9ac99", - "0x28981b14353a28bc46758dff412ac544d16f2ffc8dde31867855592ea054ab1", + "0x5754961d70d6f39d0e2c71a1a4ff5df0a26b1ceda4881ca82898994379e1e73", + "0x692381bba0e8505a8e0b92d0f046c8272de9e65f050850df678a0c10d8781d", }) blockHash := utils.TestHexToFelt(t, "0xbeef") @@ -212,14 +212,14 @@ func TestBlockWithTxHashes(t *testing.T) { ExpectedErr: nil, }, { - BlockID: WithBlockHash(utils.TestHexToFelt(t, "0x6c2fe3db009a2e008c2d65fca14204f3405cb74742fcf685f02473acaf70c72")), + BlockID: WithBlockHash(utils.TestHexToFelt(t, "0x6df565874b2ea6a02d346a23f9efb0b26abbf5708b51bb12587f88a49052964")), ExpectedErr: nil, - ExpectedBlockWithTxHashes: &blockGoerli310370, + ExpectedBlockWithTxHashes: &blockSepolia64159, }, { - BlockID: WithBlockNumber(310370), + BlockID: WithBlockNumber(64159), ExpectedErr: nil, - ExpectedBlockWithTxHashes: &blockGoerli310370, + ExpectedBlockWithTxHashes: &blockSepolia64159, }, }, "mainnet": {}, @@ -277,7 +277,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 fullBlockSepolia64159 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,6 +286,8 @@ func TestBlockWithTxHashes(t *testing.T) { // Returns: // // none +// +// TODO: implement on mainnet (v0 is deprecated) func TestBlockWithTxsAndInvokeTXNV0(t *testing.T) { testConfig := beforeEach(t) @@ -297,66 +299,9 @@ func TestBlockWithTxsAndInvokeTXNV0(t *testing.T) { want *Block } - var fullBlockGoerli310370 = 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"), - Timestamp: 1661450764, - }, - Status: "ACCEPTED_ON_L1", - Transactions: []BlockTransaction{ - - BlockInvokeTxnV0{ - TransactionHash: utils.TestHexToFelt(t, "0x40c82f79dd2bc1953fc9b347a3e7ab40fe218ed5740bf4e120f74e8a3c9ac99"), - InvokeTxnV0: InvokeTxnV0{ - Type: "INVOKE", - MaxFee: utils.TestHexToFelt(t, "0xde0b6b3a7640000"), - Version: TransactionV0, - Signature: []*felt.Felt{ - utils.TestHexToFelt(t, "0x7bc0a22005a54ec6a005c1e89ab0201cbd0819621edd9fe4d5ef177a4ff33dd"), - utils.TestHexToFelt(t, "0x13089e5f38de4ea98e9275be7fadc915946be15c14a8fed7c55202818527bea"), - }, - 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"), - }, - }, - }, - }, - }, - } - testSet := map[string][]testSetType{ - "mock": {}, - "testnet": { - { - BlockID: WithBlockTag("latest"), - ExpectedError: nil, - }, - { - BlockID: WithBlockHash(utils.TestHexToFelt(t, "0x6c2fe3db009a2e008c2d65fca14204f3405cb74742fcf685f02473acaf70c72")), - ExpectedError: nil, - want: &fullBlockGoerli310370, - }, - { - BlockID: WithBlockNumber(310370), - ExpectedError: nil, - want: &fullBlockGoerli310370, - }, - }, + "mock": {}, + "testnet": {}, "mainnet": {}, }[testEnv] @@ -411,7 +356,7 @@ func TestBlockWithTxsAndInvokeTXNV0(t *testing.T) { // 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 (fullBlockSepolia65204, fullBlockSepolia65083 and fullBlockSepoliai65212). // 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. @@ -438,82 +383,105 @@ func TestBlockWithTxsAndDeployOrDeclare(t *testing.T) { } // TODO : re-add test for deploy account transaction - var fullBlockGoerli310843 = Block{ + var fullBlockSepolia65204 = 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, "0x2b0d32dbe49e0ffdc6d5cb36896198c242276ec63a60106a17963427f7cf10e"), + ParentHash: utils.TestHexToFelt(t, "0x7c703a06d7476055adaa518cb9682621755e7a95f144a54853ace320800e82e"), + SequencerAddress: utils.TestHexToFelt(t, "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"), + BlockNumber: 65204, + NewRoot: utils.TestHexToFelt(t, "0x1a24db193c0ebab47cb29c59ef277033d2e37dd909297073cb5c9594d892344"), + Timestamp: 1715289398, }, Status: "ACCEPTED_ON_L1", Transactions: []BlockTransaction{ - BlockDeployTxn{ - TransactionHash: utils.TestHexToFelt(t, "0x35bd2978d2061b3463498f83c09322ed6a82e4b2a188506525e272a7adcdf6a"), - DeployTxn: DeployTxn{ - ClassHash: utils.TestHexToFelt(t, "0x1ca349f9721a2bf05012bb475b404313c497ca7d6d5f80c03e98ff31e9867f5"), + BlockDeployAccountTxn{ + TransactionHash: utils.TestHexToFelt(t, "0x26e30d2ed579c1ff575710d8ce29d9056e67ac08ab261a7221d384734d6ad5a"), + DeployAccountTxn: DeployAccountTxn{ + Type: TransactionType_DeployAccount, + Version: TransactionV1, + Nonce: utils.TestHexToFelt(t, "0x0"), + MaxFee: utils.TestHexToFelt(t, "0x4865413596"), + ContractAddressSalt: utils.TestHexToFelt(t, "0x5ffef5f00daec09457836121dcb7a8bcae97080716a292d3d8ee899d0b2597e"), + ClassHash: utils.TestHexToFelt(t, "0x13bfe114fb1cf405bfc3a7f8dbe2d91db146c17521d40dcf57e16d6b59fa8e6"), ConstructorCalldata: []*felt.Felt{ - utils.TestHexToFelt(t, "0x31ad196615d50956d98be085eb1774624106a6936c7c38696e730d2a6df735a"), - utils.TestHexToFelt(t, "0x736affc32af71f8d361c855b38ffef58ec151bd8361a3b160017b90ada1068e"), + utils.TestHexToFelt(t, "0x5ffef5f00daec09457836121dcb7a8bcae97080716a292d3d8ee899d0b2597e"), + }, + Signature: []*felt.Felt{ + utils.TestHexToFelt(t, "0x561486f318c01d7d47434875d685a505c282804616ed3c69e91fb59731739fc"), + utils.TestHexToFelt(t, "0x1beb073a4cac8b344d22e2d2833ea30e140b3701936b3a4af69a12a2f47394b"), + utils.TestHexToFelt(t, "0x816dd0297efc55dc1e7559020a3a825e81ef734b558f03c83325d4da7e6253"), + utils.TestHexToFelt(t, "0x0"), + utils.TestHexToFelt(t, "0x0"), + utils.TestHexToFelt(t, "0x0"), + utils.TestHexToFelt(t, "0x0"), + utils.TestHexToFelt(t, "0x0"), + utils.TestHexToFelt(t, "0x0"), + utils.TestHexToFelt(t, "0x0"), + utils.TestHexToFelt(t, "0x0"), + utils.TestHexToFelt(t, "0x0"), + utils.TestHexToFelt(t, "0x534e5f5345504f4c4941"), + utils.TestHexToFelt(t, "0x1f58325efbae915a4ea70270c536fa1c84c48eedf8ae3b970e0c0270694ddad"), + utils.TestHexToFelt(t, "0x2c7adff34d5e2b1c4205c80638df0e3a5b6831ff1d9643f6e7b8bcbbe1f71f3"), }, - ContractAddressSalt: utils.TestHexToFelt(t, "0x4241e90ee6a33a1e2e70b088f7e4acfb3d6630964c1a85e96fa96acd56dcfcf"), - - Type: "DEPLOY", - Version: TransactionV0, }, }, }, } - var fullBlockGoerli848622 = Block{ + var fullBlockSepolia65083 = Block{ BlockHeader: BlockHeader{ - BlockHash: utils.TestHexToFelt(t, "0x32964e2e407bb9e71b2de8d9d9829b0537df7c4624e1816e6cece80781ab9cc"), - ParentHash: utils.TestHexToFelt(t, "0xecbed6cfe85c77f2f8acefe2effbda817f71ca7457f7ece8262d65cc87a9f7"), + BlockHash: utils.TestHexToFelt(t, "0x549770b5b74df90276277ff7a11af881c998dffa452f4156f14446db6005174"), + ParentHash: utils.TestHexToFelt(t, "0x4de1acdff24acba2a537ef651ec8f790e5c0321f92f1115b272a6f2f2d637e8"), SequencerAddress: utils.TestHexToFelt(t, "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"), - BlockNumber: 848622, - NewRoot: utils.TestHexToFelt(t, "07c4302f09f6a72129679378e9b8d6c67774c5c4e80b1fc186da114f71637b2e"), - Timestamp: 1692416283, + BlockNumber: 65083, + NewRoot: utils.TestHexToFelt(t, "0x7df132d80333fd54a3a059e0cc6e851bda52cc72d0437a8f13a1b0809a17499"), + Timestamp: 1715244926, }, Status: "ACCEPTED_ON_L1", Transactions: []BlockTransaction{ BlockDeclareTxnV1{ - TransactionHash: utils.TestHexToFelt(t, "0x5ad2f85499ea92d33d4a44c8cd4640d1ee4e25c3ee6df0bdf0a76c12c052f0a"), + TransactionHash: utils.TestHexToFelt(t, "0x3c7817502dac2dc90198c6b64b85f3700507d74c75e08af85164e1b35e3a8b5"), 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, "0xde0b6b3a7640000"), + Version: TransactionV1, + Signature: []*felt.Felt{ + utils.TestHexToFelt(t, "0x998b12c82d208af7c4b820626f2f7e015b8ee33ef5ae44e8a04f5254977865"), + utils.TestHexToFelt(t, "0x55c341329a881afb29462ab32dcebb16d35c56021c3595bbba01b5c563f66fe"), + }, + Nonce: utils.TestHexToFelt(t, "0x713"), + ClassHash: utils.TestHexToFelt(t, "0x6c5a3f54e8bbfe07167c87f8ace70629573e05c385fe4bea69bc1d323acb8d3"), + SenderAddress: utils.TestHexToFelt(t, "0x2cc631ca0c544639f6e4403b8f3611696a3d831e8157ea1c946e35429c7ac31"), }, }, }, } - var fullBlockGoerli849399 = Block{ + var fullBlockSepoliai65212 = Block{ BlockHeader: BlockHeader{ - BlockHash: utils.TestHexToFelt(t, "0x6e5b26127400bac0cd1f3c2ab6e76850ec457c71b1f2fc7cda755bee8a1102a"), - ParentHash: utils.TestHexToFelt(t, "0x7cd085d4ab95b3307303cb836ab49c0fbc8d1f9befdcfdc65292d99c9466d05"), + BlockHash: utils.TestHexToFelt(t, "0x31b785f0f8b258f7b164d13ecc02dc4e06a1c67174f1e39f9368d1b5af43ae"), + ParentHash: utils.TestHexToFelt(t, "0x6133d377632092e31b0adad5a6496c8468cb3cb53de10f3ecdfc748f57cf9e3"), SequencerAddress: utils.TestHexToFelt(t, "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"), - BlockNumber: 849399, - NewRoot: utils.TestHexToFelt(t, "0x239a44410e78665f41f7a65ef3b5ed244ce411965498a83f80f904e22df1045"), - Timestamp: 1692560305, + BlockNumber: 65212, + NewRoot: utils.TestHexToFelt(t, "0x2d867e8a51807513d3372cf2658f03b0c212caba0fcad4f036e3023215b27a"), + Timestamp: 1715292305, }, Status: "ACCEPTED_ON_L1", Transactions: []BlockTransaction{ BlockDeclareTxnV2{ - TransactionHash: utils.TestHexToFelt(t, "0x45d04652ba51685b7b82fc17b3d5741a7c43992369c0b0aebd60916fa23b9b2"), + TransactionHash: utils.TestHexToFelt(t, "0x3e68091ecacab5a880ae8d9847d7b87408bbf05270ded34e082577acfdc3770"), 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, "0x1108942d5866"), + Version: TransactionV2, + Signature: []*felt.Felt{ + utils.TestHexToFelt(t, "0x40cedf50ffc6866050b63e9576333da68ed51e258c6ddfa7e22d5e557f71961"), + utils.TestHexToFelt(t, "0x4b33458a2005664fbd204331c078df3ac5a16288285ba0fcf1b6fd9c9d9257a"), + }, + Nonce: utils.TestHexToFelt(t, "0x2f"), + ClassHash: utils.TestHexToFelt(t, "0x190c14ee771ed5c77a006545659baa33d22c083473c8ba136cf1614f3e545b0"), + CompiledClassHash: utils.TestHexToFelt(t, "0x3bd32e501b720756105de78796bebd5f4412da986811dff38a114be296e6120"), + SenderAddress: utils.TestHexToFelt(t, "0x3b2d6d0edcbdbdf6548d2b79531263628887454a0a608762c71056172d36240"), }, }, }, @@ -527,46 +495,46 @@ func TestBlockWithTxsAndDeployOrDeclare(t *testing.T) { ExpectedError: nil, }, { - BlockID: WithBlockHash(utils.TestHexToFelt(t, "0x424fba26a7760b63895abe0c366c2d254cb47090c6f9e91ba2b3fa0824d4fc9")), + BlockID: WithBlockHash(utils.TestHexToFelt(t, "0x2b0d32dbe49e0ffdc6d5cb36896198c242276ec63a60106a17963427f7cf10e")), ExpectedError: nil, - LookupTxnPositionInOriginal: 14, + LookupTxnPositionInOriginal: 5, LookupTxnPositionInExpected: 0, - ExpectedBlockWithTxs: &fullBlockGoerli310843, + ExpectedBlockWithTxs: &fullBlockSepolia65204, }, { - BlockID: WithBlockNumber(310843), + BlockID: WithBlockNumber(65204), ExpectedError: nil, - LookupTxnPositionInOriginal: 14, + LookupTxnPositionInOriginal: 5, LookupTxnPositionInExpected: 0, - ExpectedBlockWithTxs: &fullBlockGoerli310843, + ExpectedBlockWithTxs: &fullBlockSepolia65204, }, { - BlockID: WithBlockNumber(849399), + BlockID: WithBlockNumber(65212), ExpectedError: nil, - LookupTxnPositionInOriginal: 71, + LookupTxnPositionInOriginal: 24, LookupTxnPositionInExpected: 0, - ExpectedBlockWithTxs: &fullBlockGoerli849399, + ExpectedBlockWithTxs: &fullBlockSepoliai65212, }, { - BlockID: WithBlockNumber(848622), + BlockID: WithBlockNumber(65083), ExpectedError: nil, - LookupTxnPositionInOriginal: 6, + LookupTxnPositionInOriginal: 26, LookupTxnPositionInExpected: 0, - ExpectedBlockWithTxs: &fullBlockGoerli848622, + ExpectedBlockWithTxs: &fullBlockSepolia65083, }, { - BlockID: WithBlockNumber(849399), + BlockID: WithBlockNumber(65212), ExpectedError: nil, - LookupTxnPositionInOriginal: 71, + LookupTxnPositionInOriginal: 24, LookupTxnPositionInExpected: 0, - ExpectedBlockWithTxs: &fullBlockGoerli849399, + ExpectedBlockWithTxs: &fullBlockSepoliai65212, }, { - BlockID: WithBlockNumber(848622), + BlockID: WithBlockNumber(65083), ExpectedError: nil, - LookupTxnPositionInOriginal: 6, + LookupTxnPositionInOriginal: 26, LookupTxnPositionInExpected: 0, - ExpectedBlockWithTxs: &fullBlockGoerli848622, + ExpectedBlockWithTxs: &fullBlockSepolia65083, }, }, "mainnet": {}, @@ -639,14 +607,14 @@ func TestBlockTransactionCount(t *testing.T) { testSet := map[string][]testSetType{ "mock": { { - BlockID: WithBlockNumber(300000), + BlockID: WithBlockNumber(30000), ExpectedCount: 10, }, }, "testnet": { { - BlockID: WithBlockNumber(300000), - ExpectedCount: 23, + BlockID: WithBlockNumber(30000), + ExpectedCount: 4, }, }, "mainnet": {}, @@ -692,8 +660,8 @@ func TestCaptureUnsupportedBlockTxn(t *testing.T) { "mock": {}, "testnet": { { - StartBlock: 381000, - EndBlock: 381001, + StartBlock: 38100, + EndBlock: 38101, }, }, "mainnet": {}, @@ -732,27 +700,94 @@ func TestCaptureUnsupportedBlockTxn(t *testing.T) { // Returns: // // none -// -// TODO: Find a block with such a Txn func TestBlockWithTxsAndInvokeTXNV1(t *testing.T) { - _ = beforeEach(t) + testConfig := beforeEach(t) type testSetType struct { - check bool + BlockID BlockID + ExpectedError error + LookupTxnPositionInOriginal int + LookupTxnPositionInExpected int + want *Block } + + var fullBlockSepolia64159 = Block{ + BlockHeader: BlockHeader{ + BlockHash: utils.TestHexToFelt(t, "0x6df565874b2ea6a02d346a23f9efb0b26abbf5708b51bb12587f88a49052964"), + ParentHash: utils.TestHexToFelt(t, "0x1406ec9385293905d6c20e9c5aa0bbf9f63f87d39cf12fcdfef3ed0d056c0f5"), + SequencerAddress: utils.TestHexToFelt(t, "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"), + BlockNumber: 64159, + NewRoot: utils.TestHexToFelt(t, "0x310be818a18de0d6f6c1391f467d0dbd1a2753e6dde876449448465f8e617f0"), + Timestamp: 1714901729, + }, + Status: "ACCEPTED_ON_L1", + Transactions: []BlockTransaction{ + + BlockInvokeTxnV1{ + TransactionHash: utils.TestHexToFelt(t, "0x5f14364b746abcfdfc0280877ff6d18c311d363e62264d7f218c5da2d396acc"), + InvokeTxnV1: InvokeTxnV1{ + Type: "INVOKE", + Version: TransactionV1, + Nonce: utils.TestHexToFelt(t, "0x33"), + MaxFee: utils.TestHexToFelt(t, "0x1bad55a98e1c1"), + SenderAddress: utils.TestHexToFelt(t, "0x3543d2f0290e39a08cfdf2245f14aec7dca60672b7c7458375f3cb3834e1067"), + Signature: []*felt.Felt{ + utils.TestHexToFelt(t, "0x1"), + utils.TestHexToFelt(t, "0x7bc0a22005a54ec6a005c1e89ab0201cbd0819621edd9fe4d5ef177a4ff33dd"), + utils.TestHexToFelt(t, "0x13089e5f38de4ea98e9275be7fadc915946be15c14a8fed7c55202818527bea"), + }, + Calldata: []*felt.Felt{ + utils.TestHexToFelt(t, "0x1"), + utils.TestHexToFelt(t, "0x517567ac7026ce129c950e6e113e437aa3c83716cd61481c6bb8c5057e6923e"), + utils.TestHexToFelt(t, "0xcaffbd1bd76bd7f24a3fa1d69d1b2588a86d1f9d2359b13f6a84b7e1cbd126"), + utils.TestHexToFelt(t, "0x6"), + utils.TestHexToFelt(t, "0x5265706f73736573734275696c64696e67"), + utils.TestHexToFelt(t, "0x4"), + utils.TestHexToFelt(t, "0x5"), + utils.TestHexToFelt(t, "0x1b48"), + utils.TestHexToFelt(t, "0x1"), + utils.TestHexToFelt(t, "0xe52"), + }, + }, + }, + }, + } + testSet := map[string][]testSetType{ "mock": {}, "testnet": { { - check: false, + BlockID: WithBlockNumber(64159), + ExpectedError: nil, + want: &fullBlockSepolia64159, + LookupTxnPositionInExpected: 0, + LookupTxnPositionInOriginal: 4, }, }, "mainnet": {}, }[testEnv] + + require := require.New(t) for _, test := range testSet { - if test.check { - t.Fatalf("error running test: %v", ErrNotImplemented) - } + spy := NewSpy(testConfig.provider.c) + testConfig.provider.c = spy + blockWithTxsInterface, err := testConfig.provider.BlockWithTxs(context.Background(), test.BlockID) + require.NoError(err, "Unable to fetch the given block.") + + blockWithTxs, ok := blockWithTxsInterface.(*Block) + require.True(ok, "Failed to assert the Interface as *Block.") + require.Equal(blockWithTxs.BlockHash.String()[:2], "0x", "Block Hash should start with \"0x\".") + require.NotEqual(len(blockWithTxs.Transactions), 0, "The number of transaction should not be 0.") + + invokeV1Want, ok := (*test.want).Transactions[test.LookupTxnPositionInExpected].(BlockInvokeTxnV1) + require.True(ok, "Expected invoke v1 transaction.") + + invokeV1Block, ok := blockWithTxs.Transactions[test.LookupTxnPositionInOriginal].(BlockInvokeTxnV1) + require.True(ok, "Expected invoke v1 transaction.") + + require.Equal(invokeV1Want.TransactionHash.String(), invokeV1Block.TransactionHash.String(), "Expected equal TransactionHash.") + require.Equal(invokeV1Want.InvokeTxnV1.MaxFee.String(), invokeV1Block.InvokeTxnV1.MaxFee.String(), "Expected equal maxfee.") + require.Equal(invokeV1Want.InvokeTxnV1.Calldata[1].String(), invokeV1Block.InvokeTxnV1.Calldata[1].String(), "Expected equal calldatas.") } } @@ -783,7 +818,7 @@ func TestStateUpdate(t *testing.T) { testSet := map[string][]testSetType{ "mock": { { - BlockID: WithBlockNumber(300000), + BlockID: WithBlockNumber(30000), ExpectedStateUpdateOutput: StateUpdateOutput{ BlockHash: utils.TestHexToFelt(t, "0x4f1cee281edb6cb31b9ba5a8530694b5527cf05c5ac6502decf3acb1d0cec4"), NewRoot: utils.TestHexToFelt(t, "0x70677cda9269d47da3ff63bc87cf1c87d0ce167b05da295dc7fc68242b250b"), @@ -806,22 +841,121 @@ func TestStateUpdate(t *testing.T) { }, "testnet": { { - BlockID: WithBlockNumber(300000), + BlockID: WithBlockNumber(30000), ExpectedStateUpdateOutput: StateUpdateOutput{ - BlockHash: utils.TestHexToFelt(t, "0x03b6d94b246815960f38b7dffc53cda192e7d1dcfff61e1bc042fb57e95f8349"), - NewRoot: utils.TestHexToFelt(t, "0x70677cda9269d47da3ff63bc87cf1c87d0ce167b05da295dc7fc68242b250b"), + BlockHash: utils.TestHexToFelt(t, "0x62ab7b3ade3e7c26d0f50cb539c621b679e07440685d639904663213f906938"), + NewRoot: utils.TestHexToFelt(t, "0x491250c959067f21177f50cfdfede2bd9c8f2597f4ed071dbdba4a7ee3dabec"), PendingStateUpdate: PendingStateUpdate{ - OldRoot: utils.TestHexToFelt(t, "0x19aa982a75263d4c4de4cc4c5d75c3dec32e00b95bef7bbb4d17762a0b138af"), + OldRoot: utils.TestHexToFelt(t, "0x1d2922de7bb14766d0c3aa323876d9f5a4b1733f6dc199bbe596d06dd8f70e4"), StateDiff: StateDiff{ - StorageDiffs: []ContractStorageDiffItem{{ - Address: utils.TestHexToFelt(t, "0xe5cc6f2b6d34979184b88334eb64173fe4300cab46ecd3229633fcc45c83d4"), - StorageEntries: []StorageEntry{ - { - Key: utils.TestHexToFelt(t, "0x1813aac5f5e7799684c6dc33e51f44d3627fd748c800724a184ed5be09b713e"), - Value: utils.TestHexToFelt(t, "0x630b4197"), + StorageDiffs: []ContractStorageDiffItem{ + { + Address: utils.TestHexToFelt(t, "0xe5cc6f2b6d34979184b88334eb64173fe4300cab46ecd3229633fcc45c83d4"), + StorageEntries: []StorageEntry{ + { + Key: utils.TestHexToFelt(t, "0x1813aac5f5e7799684c6dc33e51f44d3627fd748c800724a184ed5be09b713e"), + Value: utils.TestHexToFelt(t, "0x630b4197"), + }, }, }, - }}, + { + Address: utils.TestHexToFelt(t, "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"), + StorageEntries: []StorageEntry{ + { + Key: utils.TestHexToFelt(t, "0x7b3303ee433d39925f7c289cd2048052a2d8e2d653bdd7cdfa6a6ab8365445d"), + Value: utils.TestHexToFelt(t, "0x462893a80b9b5834"), + }, + { + Key: utils.TestHexToFelt(t, "0x5496768776e3db30053404f18067d81a6e06f5a2b0de326e21298fd9d569a9a"), + Value: utils.TestHexToFelt(t, "0x1bc48439cb7402fb6"), + }, + }, + }, + { + Address: utils.TestHexToFelt(t, "0x36031daa264c24520b11d93af622c848b2499b66b41d611bac95e13cfca131a"), + StorageEntries: []StorageEntry{ + { + Key: utils.TestHexToFelt(t, "0x6f64efd140d53af83432093bb6c3d5e8db645bd89feead6dda806955f68ef2a"), + Value: utils.TestHexToFelt(t, "0x3df78515979000000000000000000000000065bfec4b"), + }, + { + Key: utils.TestHexToFelt(t, "0x143dae8bc0e9898f65cb1eb84f16bfb9cb09431972541141677721dd541f055"), + Value: utils.TestHexToFelt(t, "0x5f35296000000000000000000000000065bfec4c"), + }, + { + Key: utils.TestHexToFelt(t, "0x2d04b0419a0e89f6b4dabc3dc19b087e71f0dec9f1785606f00517d3468636b"), + Value: utils.TestHexToFelt(t, "0x5f5f2e4000000000000000000000000065bfec4c"), + }, + { + Key: utils.TestHexToFelt(t, "0x55c3ad197a2fa1dce3a999ae803099406fab085f187b926e7e1f0e38592043d"), + Value: utils.TestHexToFelt(t, "0x3985cb98c08000000000000000000000000065bfec4b"), + }, + { + Key: utils.TestHexToFelt(t, "0x8653303a2624a587179380e17d7876d346aea7f02dbd57782950500ea7276e"), + Value: utils.TestHexToFelt(t, "0x3e076b4dfa2000000000000000000000000065bfec4b"), + }, + { + Key: utils.TestHexToFelt(t, "0x56041f8991ff7eff841647cfda1f1cfb9e7321c5a96c53d4a5072497de6b50f"), + Value: utils.TestHexToFelt(t, "0x23b8c472000000000000000000000000065bfec4c"), + }, + { + Key: utils.TestHexToFelt(t, "0x6a6414ca66551a2324e436ed37d069f1660ef01bc3fe90497fc729ee60781b8"), + Value: utils.TestHexToFelt(t, "0x3511a8db1d000000000000000000000000065bfec4b"), + }, + { + Key: utils.TestHexToFelt(t, "0x437f038e1991939def57775a3405a3b6f0c0830f09d0e6cfc309393950fa773"), + Value: utils.TestHexToFelt(t, "0x3d5e14753a000000000000000000000000065bfec4c"), + }, + { + Key: utils.TestHexToFelt(t, "0x7b4de97b546ed17a0d490dab334867e9383e029411c268a8902768b6da6a2eb"), + Value: utils.TestHexToFelt(t, "0x5f38d0b000000000000000000000000065bfec4b"), + }, + { + Key: utils.TestHexToFelt(t, "0x28e86558bd7c5a9c26fceeafb9570eb7b3011db4a9ff813b318f91129935c37"), + Value: utils.TestHexToFelt(t, "0xf423c000000000000000000000000065bfec4c"), + }, + { + Key: utils.TestHexToFelt(t, "0x1b3f3d264a9c63c581333d4b97c556b6f20f9a1abf64c7f71e04b35df62cc70"), + Value: utils.TestHexToFelt(t, "0xf407f000000000000000000000000065bfec4c"), + }, + }, + }, + { + Address: utils.TestHexToFelt(t, "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"), + StorageEntries: []StorageEntry{ + { + Key: utils.TestHexToFelt(t, "0x5496768776e3db30053404f18067d81a6e06f5a2b0de326e21298fd9d569a9a"), + Value: utils.TestHexToFelt(t, "0x5d8da32bae8513cfa"), + }, + { + Key: utils.TestHexToFelt(t, "0x295c615dc08b568dce79348e5dd16f45bc6458ddb026f09e16ce03f3c68e12e"), + Value: utils.TestHexToFelt(t, "0x218cbd49b5dafd0cec6"), + }, + }, + }, + { + Address: utils.TestHexToFelt(t, "0x47ad6a25df680763e5663bd0eba3d2bfd18b24b1e8f6bd36b71c37433c63ed0"), + StorageEntries: []StorageEntry{ + { + Key: utils.TestHexToFelt(t, "0x38b0933d0e83013f5bd5aee82962149fed820534bfc3978a5180646208e7937"), + Value: utils.TestHexToFelt(t, "0x7df9d41833d7cf135b059ccc165ed4332cc32ac3eddf3f6239594731b0d8c8"), + }, + { + Key: utils.TestHexToFelt(t, "0x38b0933d0e83013f5bd5aee82962149fed820534bfc3978a5180646208e7936"), + Value: utils.TestHexToFelt(t, "0x3b2f128039c288928ff492627eba9969d760b7fd0b16f3d39aa18f1f8744765"), + }, + }, + }, + { + Address: utils.TestHexToFelt(t, "0x1"), + StorageEntries: []StorageEntry{ + { + Key: utils.TestHexToFelt(t, "0x7526"), + Value: utils.TestHexToFelt(t, "0x32f159b038c06f9829d8ee63db1556a3390265b0b49b89c48235b6f77326339"), + }, + }, + }, + }, }, }, }, diff --git a/rpc/mock_test.go b/rpc/mock_test.go index 765da088..656e307f 100644 --- a/rpc/mock_test.go +++ b/rpc/mock_test.go @@ -981,8 +981,8 @@ func mock_starknet_getBlockWithTxHashes(result interface{}, method string, args } txHashes, err := utils.HexArrToFelt([]string{ - "0x40c82f79dd2bc1953fc9b347a3e7ab40fe218ed5740bf4e120f74e8a3c9ac99", - "0x28981b14353a28bc46758dff412ac544d16f2ffc8dde31867855592ea054ab1", + "0x5754961d70d6f39d0e2c71a1a4ff5df0a26b1ceda4881ca82898994379e1e73", + "0x692381bba0e8505a8e0b92d0f046c8272de9e65f050850df678a0c10d8781d", }) if err != nil { return err diff --git a/rpc/provider_test.go b/rpc/provider_test.go index 661d8bea..cb5966ca 100644 --- a/rpc/provider_test.go +++ b/rpc/provider_test.go @@ -48,10 +48,10 @@ var ( // Requires a Testnet Starknet JSON-RPC compliant node (e.g. pathfinder) // (ref: https://github.com/eqlabs/pathfinder) "testnet": { - base: "http://localhost:9545/v0.2/rpc", + base: "https://free-rpc.nethermind.io/sepolia-juno", }, // Requires a Devnet configuration running locally - // (ref: https://github.com/Shard-Labs/starknet-devnet) + // (ref: https://github.com/0xSpaceShard/starknet-devnet-rs) "devnet": { base: "http://localhost:5050/rpc", }, @@ -101,7 +101,6 @@ func beforeEach(t *testing.T) *testConfiguration { return &testConfig } - testConfig.base = "https://free-rpc.nethermind.io/sepolia-juno" base := os.Getenv("INTEGRATION_BASE") if base != "" { testConfig.base = base From c76fd3fc70aaca9d1fb5243a9238e69d80334b1c Mon Sep 17 00:00:00 2001 From: Aryan Godara <65490434+AryanGodara@users.noreply.github.com> Date: Thu, 16 May 2024 19:08:02 +0530 Subject: [PATCH 3/3] Update transaction tests to sepolia (#557) * update transaction_test.go, goerli to sepolia --------- Co-authored-by: rian Co-authored-by: Rian Hughes --- account/account_test.go | 7 +- rpc/mock_test.go | 127 +++++----- ...155ad0a2f7e2a0fd9b057b90cdd64eba7e12e.json | 54 ---- ...60c39d3a668fe12f117ecedb9749466d8352b.json | 46 ++++ rpc/transaction.go | 24 +- rpc/transaction_test.go | 238 +++++++++--------- rpc/types_block_transaction.go | 90 +++---- rpc/types_transaction.go | 36 +-- rpc/types_transaction_receipt.go | 213 +++++++--------- 9 files changed, 390 insertions(+), 445 deletions(-) delete mode 100644 rpc/tests/receipt/0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e.json create mode 100644 rpc/tests/receipt/0xf2f3d50192637e8d5e817363460c39d3a668fe12f117ecedb9749466d8352b.json diff --git a/account/account_test.go b/account/account_test.go index c95223e9..7eb26e35 100644 --- a/account/account_test.go +++ b/account/account_test.go @@ -970,10 +970,9 @@ func TestWaitForTransactionReceiptMOCK(t *testing.T) { Hash: new(felt.Felt).SetUint64(2), ShouldCallTransactionReceipt: true, ExpectedReceipt: &rpc.TransactionReceiptWithBlockInfo{ - TransactionReceipt: rpc.InvokeTransactionReceipt{ - TransactionHash: new(felt.Felt).SetUint64(2), - ExecutionStatus: rpc.TxnExecutionStatusSUCCEEDED, - }, + UnknownTransactionReceipt: rpc.UnknownTransactionReceipt{}, + BlockHash: new(felt.Felt).SetUint64(2), + BlockNumber: 2, }, ExpectedErr: nil, diff --git a/rpc/mock_test.go b/rpc/mock_test.go index 656e307f..8f04cde0 100644 --- a/rpc/mock_test.go +++ b/rpc/mock_test.go @@ -197,24 +197,58 @@ func mock_starknet_getTransactionByBlockIdAndIndex(result interface{}, method st return errWrongArgs } - var InvokeTxnV1example = `{ - "transaction_hash": "0x705547f8f2f8fdfb10ed533d909f76482bb293c5a32648d476774516a0bebd0", + var InvokeTxnV3Example = `{ "type": "INVOKE", - "nonce": "0x0", - "max_fee": "0x53685de02fa5", - "version": "0x1", + "sender_address": "0x143fe26927dd6a302522ea1cd6a821ab06b3753194acee38d88a85c93b3cbc6", + "calldata": [ + "0x1", + "0x6b74c515944ef1ef630ee1cf08a22e110c39e217fa15554a089182a11f78ed", + "0xc844fd57777b0cd7e75c8ea68deec0adf964a6308da7a58de32364b7131cc8", + "0x13", + "0x41bbf1eff2ac123d9e01004a385329369cbc1c309838562f030b3faa2caa4", + "0x54103", + "0x7e430a7a59836b5969859b25379c640a8ccb66fb142606d7acb1a5563c2ad9", + "0x6600d829", + "0x103020400000000000000000000000000000000000000000000000000000000", + "0x4", + "0x5f5e100", + "0x5f60fc2", + "0x5f60fc2", + "0x5f6570d", + "0xa07695b6574c60c37", + "0x1", + "0x2", + "0x7afe11c6cdf846e8e33ff55c6e8310293b81aa58da4618af0c2fb29db2515c7", + "0x1200966b0f9a5cd1bf7217b202c3a4073a1ff583e4779a3a3ffb97a532fe0c", + "0x2cb74dff29a13dd5d855159349ec92f943bacf0547ff3734e7d84a15d08cbc5", + "0x460769330eab4b3269a5c07369382fcc09fbfc92458c63f77292425c72272f9", + "0x10ebdb197fd1017254b927b01073c64a368db45534413b539895768e57b72ba", + "0x2e7dc996ebf724c1cf18d668fc3455df4245749ebc0724101cbc6c9cb13c962" + ], + "version": "0x3", "signature": [ - "0x4a7849de7b91e52cd0cdaf4f40aa67f54a58e25a15c60e034d2be819c1ecda4", - "0x227fcad2a0007348e64384649365e06d41287b1887999b406389ee73c1d8c4c" + "0x665f0c67ed4d9565f63857b1a55974b98b2411f579c53c9f903fd21a3edb3d1", + "0x549c4480aba4753c58f757c92b5a1d3d67b2ced4bf06076825af3f52f738d6d" ], - "sender_address": "0x315e364b162653e5c7b23efd34f8da27ba9c069b68e3042b7d76ce1df890313", - "calldata": [ - "0x1", - "0x13befe6eda920ce4af05a50a67bd808d67eee6ba47bb0892bef2d630eaf1bba" - ] - }` - - if err := json.Unmarshal([]byte(InvokeTxnV1example), r); err != nil { + "nonce": "0x359d", + "resource_bounds": { + "l1_gas": { + "max_amount": "0x3bb2", + "max_price_per_unit": "0x2ba7def30000" + }, + "l2_gas": { + "max_amount": "0x0", + "max_price_per_unit": "0x0" + } + }, + "tip": "0x0", + "paymaster_data": [], + "account_deployment_data": [], + "nonce_data_availability_mode": "L1", + "fee_data_availability_mode": "L1" + }` + + if err := json.Unmarshal([]byte(InvokeTxnV3Example), r); err != nil { return err } return nil @@ -269,45 +303,21 @@ func mock_starknet_getTransactionByHash(result interface{}, method string, args return errWrongArgs } - var InvokeTxnV1example = ` { - "transaction_hash": "0x1779df1c6de5136ad2620f704b645e9cbd554b57d37f08a06ea60142269c5a5", - "version": "0x1", - "max_fee": "0x17970b794f000", + var DeclareTnxV2Example = `{ + "type": "DECLARE", + "sender_address": "0x5fd4befee268bf6880f955875cbed3ade8346b1f1e149cc87b317e62b6db569", + "compiled_class_hash": "0x7130f75fc2f1400813d1e96ea7ebee334b568a87b645a62aade0eb2fa2cf252", + "max_fee": "0x4a0fbb2d7a43", + "version": "0x2", "signature": [ - "0xe500c4014c055c3304d8a125cfef44638ffa5b0f6840916049667a4c38aa1c", - "0x45ac538bfce5d8c5741b4421bbdc99f5849451acae75d2048d7cc4bb029ca77" + "0x5569787df42fece1184537b0d480900a403386355b9d6a59e7c7a7e758287f0", + "0x2acaeea2e0817da33ed5dbeec295b0177819b5a5a50b0a669e6eecd88e42e92" ], - "nonce": "0x2d", - "sender_address": "0x66dd340c03b6b7866fa7bb4bb91cc9e9c2a8eedc321985f334fd55de5e4e071", - "calldata": [ - "0x3", - "0x39a04b968d794fb076b0fbb146c12b48a23aa785e3d2e5be1982161f7536218", - "0x2f0b3c5710379609eb5495f1ecd348cb28167711b73609fe565a72734550354", - "0x0", - "0x3", - "0x3207980cd08767c9310d197c38b1a58b2a9bceb61dd9a99f51b407798702991", - "0x2f0b3c5710379609eb5495f1ecd348cb28167711b73609fe565a72734550354", - "0x3", - "0x3", - "0x42969068f9e84e9bf1c7bb6eb627455287e58f866ba39e45b123f9656aed5e9", - "0x2f0b3c5710379609eb5495f1ecd348cb28167711b73609fe565a72734550354", - "0x6", - "0x3", - "0x9", - "0x47487560da4c5c5755897e527a5fda37422b5ba02a2aba1ca3ce2b24dfd142e", - "0xde0b6b3a7640000", - "0x0", - "0x47487560da4c5c5755897e527a5fda37422b5ba02a2aba1ca3ce2b24dfd142e", - "0x10f0cf064dd59200000", - "0x0", - "0x47487560da4c5c5755897e527a5fda37422b5ba02a2aba1ca3ce2b24dfd142e", - "0x21e19e0c9bab2400000", - "0x0" - ], - "type": "INVOKE" - }` + "nonce": "0x16e", + "class_hash": "0x79b7ec8fdf40a4ff6ed47123049dfe36b5c02db93aa77832682344775ef70c6" + }` - if err := json.Unmarshal([]byte(InvokeTxnV1example), r); err != nil { + if err := json.Unmarshal([]byte(DeclareTnxV2Example), r); err != nil { return err } return nil @@ -327,33 +337,34 @@ func mock_starknet_getTransactionReceipt(result interface{}, method string, args if !ok || r == nil { return errWrongType } - fmt.Printf("%T, %d", result, len(args)) if len(args) != 1 { return errWrongArgs } arg0Felt := args[0].(*felt.Felt) - testTxnHash, err := utils.HexToFelt("0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e") + testTxnHash, err := utils.HexToFelt("0xf2f3d50192637e8d5e817363460c39d3a668fe12f117ecedb9749466d8352b") if err != nil { return err } if arg0Felt.Equal(testTxnHash) { - var txnRec struct { - Result UnknownTransactionReceipt `json:"result"` - } - read, err := os.ReadFile("tests/receipt/0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e.json") + + var txnRec TransactionReceiptWithBlockInfo + read, err := os.ReadFile("tests/receipt/0xf2f3d50192637e8d5e817363460c39d3a668fe12f117ecedb9749466d8352b.json") if err != nil { return err } + err = json.Unmarshal(read, &txnRec) if err != nil { return err } - txnReceipt, err := json.Marshal(txnRec.Result.TransactionReceipt) + + txnReceipt, err := json.Marshal(txnRec) if err != nil { return err } + return json.Unmarshal(txnReceipt, &r) } diff --git a/rpc/tests/receipt/0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e.json b/rpc/tests/receipt/0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e.json deleted file mode 100644 index 9a7fc8d7..00000000 --- a/rpc/tests/receipt/0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "jsonrpc": "2.0", - "result": { - "type": "INVOKE", - "transaction_hash": "0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e", - "actual_fee": { - "amount": "0x30df144f446a59", - "unit": "FRI" - }, - "execution_status": "SUCCEEDED", - "finality_status": "ACCEPTED_ON_L2", - "block_hash": "0x76c781a6a9d7f4a75205cd282fadf63f0c41d5c585a6cc384a7e726ac483316", - "block_number": 332275, - "messages_sent": [], - "events": [ - { - "from_address": "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d", - "keys": [ - "0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9", - "0x14c5c28581c68f64c9a3d86b919094a5209fe0ccb454f776b3be2c3968cd91d", - "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8" - ], - "data": [ - "0x30df144f446a59", - "0x0" - ] - }, - { - "from_address": "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d", - "keys": [ - "0xa9fa878c35cd3d0191318f89033ca3e5501a3d90e21e3cc9256bdd5cd17fdd" - ], - "data": [ - "0xca46d96b37266650e0a8b79938d9300037337cad82ea4f45a921ad68b6a5f9", - "0x477bd3017f2b1cec6", - "0x0", - "0x477ee0f2c41f6391f", - "0x0" - ] - } - ], - "execution_resources": { - "steps": 7754, - "pedersen_builtin_applications": 20, - "range_check_builtin_applications": 185, - "ec_op_builtin_applications": 3, - "data_availability": { - "l1_gas": 0, - "l1_data_gas": 384 - } - } - }, - "id": 1 -} \ No newline at end of file diff --git a/rpc/tests/receipt/0xf2f3d50192637e8d5e817363460c39d3a668fe12f117ecedb9749466d8352b.json b/rpc/tests/receipt/0xf2f3d50192637e8d5e817363460c39d3a668fe12f117ecedb9749466d8352b.json new file mode 100644 index 00000000..2807b737 --- /dev/null +++ b/rpc/tests/receipt/0xf2f3d50192637e8d5e817363460c39d3a668fe12f117ecedb9749466d8352b.json @@ -0,0 +1,46 @@ +{ + "actual_fee": { + "amount": "0x16409a78a10b00", + "unit": "FRI" + }, + "block_hash": "0x4ae5d52c75e4dea5694f456069f830cfbc7bec70427eee170c3385f751b8564", + "block_number": 52767, + "events": [ + { + "data": [ + "0x3028044a4c4df95c0b0a907307c6feffa76b9c38e83088ade29b186a250eb13", + "0x3", + "0x17a393a5e943cec833c8a8f4cbbf7c58361fb2fdd9caa0c36d901eedec4938e", + "0x776731d30bd922ac0390edfc664ed31b232aa7c7ce389c333e34c6b32957532", + "0x40851db0ebaebb9f8a18eda25005c050793f2a69e9e7d1f44bc133752898918" + ], + "from_address": "0x243d436e1f7cea085aaa42834975488029b1ebf67cea1d2e86f7de58e7d34a3", + "keys": [ + "0x15bd0500dc9d7e69ab9577f73a8d753e8761bed10f25ba0f124254dc4edb8b4" + ] + }, + { + "data": [ + "0x6016d919abf2ddefe03dacc2ff5c8f42eb80cf65add1e90dd73c5c5e06ef3e2", + "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8", + "0x16409a78a10b00", + "0x0" + ], + "from_address": "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d", + "keys": [ + "0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9" + ] + } + ], + "execution_resources": { + "ec_op_builtin_applications": 3, + "pedersen_builtin_applications": 24, + "range_check_builtin_applications": 152, + "steps": 5774 + }, + "execution_status": "SUCCEEDED", + "finality_status": "ACCEPTED_ON_L1", + "messages_sent": [], + "transaction_hash": "0xf2f3d50192637e8d5e817363460c39d3a668fe12f117ecedb9749466d8352b", + "type": "INVOKE" +} \ No newline at end of file diff --git a/rpc/transaction.go b/rpc/transaction.go index 7bec3857..a920d7ab 100644 --- a/rpc/transaction.go +++ b/rpc/transaction.go @@ -9,9 +9,10 @@ import ( ) var ( - feltZero = new(felt.Felt).SetUint64(0) - feltOne = new(felt.Felt).SetUint64(1) - feltTwo = new(felt.Felt).SetUint64(2) + feltZero = new(felt.Felt).SetUint64(0) + feltOne = new(felt.Felt).SetUint64(1) + feltTwo = new(felt.Felt).SetUint64(2) + feltThree = new(felt.Felt).SetUint64(3) ) // adaptTransaction adapts a TXN to a Transaction and returns it, along with any error encountered. @@ -28,9 +29,20 @@ func adaptTransaction(t TXN) (Transaction, error) { } switch t.Type { case TransactionType_Invoke: - var tx InvokeTxnV1 - err := json.Unmarshal(txMarshalled, &tx) - return tx, err + switch { + case t.Version.Equal(feltZero): + var tx InvokeTxnV0 + err := json.Unmarshal(txMarshalled, &tx) + return tx, err + case t.Version.Equal(feltOne): + var tx InvokeTxnV1 + err := json.Unmarshal(txMarshalled, &tx) + return tx, err + case t.Version.Equal(feltThree): + var tx InvokeTxnV3 + err := json.Unmarshal(txMarshalled, &tx) + return tx, err + } case TransactionType_Declare: switch { case t.Version.Equal(feltZero): diff --git a/rpc/transaction_test.go b/rpc/transaction_test.go index 765bb553..f965ad52 100644 --- a/rpc/transaction_test.go +++ b/rpc/transaction_test.go @@ -23,54 +23,31 @@ func TestTransactionByHash(t *testing.T) { ExpectedTxn Transaction } - var InvokeTxnV1example = InvokeTxnV1{ - Type: TransactionType_Invoke, - MaxFee: utils.TestHexToFelt(t, "0x17970b794f000"), - Version: TransactionV1, - Nonce: utils.TestHexToFelt(t, "0x2d"), + var DeclareTxnV2Example = DeclareTxnV2{ + Type: TransactionType_Declare, + Version: TransactionV2, + MaxFee: utils.TestHexToFelt(t, "0x4a0fbb2d7a43"), + ClassHash: utils.TestHexToFelt(t, "0x79b7ec8fdf40a4ff6ed47123049dfe36b5c02db93aa77832682344775ef70c6"), + CompiledClassHash: utils.TestHexToFelt(t, "0x7130f75fc2f1400813d1e96ea7ebee334b568a87b645a62aade0eb2fa2cf252"), + Nonce: utils.TestHexToFelt(t, "0x16e"), Signature: []*felt.Felt{ - utils.TestHexToFelt(t, "0xe500c4014c055c3304d8a125cfef44638ffa5b0f6840916049667a4c38aa1c"), - utils.TestHexToFelt(t, "0x45ac538bfce5d8c5741b4421bbdc99f5849451acae75d2048d7cc4bb029ca77"), - }, - SenderAddress: utils.TestHexToFelt(t, "0x66dd340c03b6b7866fa7bb4bb91cc9e9c2a8eedc321985f334fd55de5e4e071"), - Calldata: []*felt.Felt{ - utils.TestHexToFelt(t, "0x3"), - utils.TestHexToFelt(t, "0x39a04b968d794fb076b0fbb146c12b48a23aa785e3d2e5be1982161f7536218"), - utils.TestHexToFelt(t, "0x2f0b3c5710379609eb5495f1ecd348cb28167711b73609fe565a72734550354"), - utils.TestHexToFelt(t, "0x0"), - utils.TestHexToFelt(t, "0x3"), - utils.TestHexToFelt(t, "0x3207980cd08767c9310d197c38b1a58b2a9bceb61dd9a99f51b407798702991"), - utils.TestHexToFelt(t, "0x2f0b3c5710379609eb5495f1ecd348cb28167711b73609fe565a72734550354"), - utils.TestHexToFelt(t, "0x3"), - utils.TestHexToFelt(t, "0x3"), - utils.TestHexToFelt(t, "0x42969068f9e84e9bf1c7bb6eb627455287e58f866ba39e45b123f9656aed5e9"), - utils.TestHexToFelt(t, "0x2f0b3c5710379609eb5495f1ecd348cb28167711b73609fe565a72734550354"), - utils.TestHexToFelt(t, "0x6"), - utils.TestHexToFelt(t, "0x3"), - utils.TestHexToFelt(t, "0x9"), - utils.TestHexToFelt(t, "0x47487560da4c5c5755897e527a5fda37422b5ba02a2aba1ca3ce2b24dfd142e"), - utils.TestHexToFelt(t, "0xde0b6b3a7640000"), - utils.TestHexToFelt(t, "0x0"), - utils.TestHexToFelt(t, "0x47487560da4c5c5755897e527a5fda37422b5ba02a2aba1ca3ce2b24dfd142e"), - utils.TestHexToFelt(t, "0x10f0cf064dd59200000"), - utils.TestHexToFelt(t, "0x0"), - utils.TestHexToFelt(t, "0x47487560da4c5c5755897e527a5fda37422b5ba02a2aba1ca3ce2b24dfd142e"), - utils.TestHexToFelt(t, "0x21e19e0c9bab2400000"), - utils.TestHexToFelt(t, "0x0"), + utils.TestHexToFelt(t, "0x5569787df42fece1184537b0d480900a403386355b9d6a59e7c7a7e758287f0"), + utils.TestHexToFelt(t, "0x2acaeea2e0817da33ed5dbeec295b0177819b5a5a50b0a669e6eecd88e42e92"), }, + SenderAddress: utils.TestHexToFelt(t, "0x5fd4befee268bf6880f955875cbed3ade8346b1f1e149cc87b317e62b6db569"), } testSet := map[string][]testSetType{ "mock": { { - TxHash: utils.TestHexToFelt(t, "0x1779df1c6de5136ad2620f704b645e9cbd554b57d37f08a06ea60142269c5a5"), - ExpectedTxn: InvokeTxnV1example, + TxHash: utils.TestHexToFelt(t, "0xd109474cd037bad60a87ba0ccf3023d5f2d1cd45220c62091d41a614d38eda"), + ExpectedTxn: DeclareTxnV2Example, }, }, "testnet": { { - TxHash: utils.TestHexToFelt(t, "0x1779df1c6de5136ad2620f704b645e9cbd554b57d37f08a06ea60142269c5a5"), - ExpectedTxn: InvokeTxnV1example, + TxHash: utils.TestHexToFelt(t, "0xd109474cd037bad60a87ba0ccf3023d5f2d1cd45220c62091d41a614d38eda"), + ExpectedTxn: DeclareTxnV2Example, }, }, "mainnet": {}, @@ -86,11 +63,11 @@ func TestTransactionByHash(t *testing.T) { t.Fatal("transaction should exist") } - txCasted, ok := (tx).(InvokeTxnV1) + txCasted, ok := (tx).(DeclareTxnV2) if !ok { - t.Fatalf("transaction should be InvokeTxnV1, instead %T", tx) + t.Fatalf("transaction should be DeclareTnxV2, instead %T", tx) } - require.Equal(t, txCasted.Type, TransactionType_Invoke) + require.Equal(t, txCasted.Type, TransactionType_Declare) require.Equal(t, txCasted, test.ExpectedTxn) } } @@ -101,7 +78,7 @@ func TestTransactionByHash(t *testing.T) { // it creates a spy object and assigns it to the provider's c field. It then calls // the TransactionByBlockIdAndIndex function with the specified block ID and index. // If there is an error, it fails the test. If the transaction is nil, it fails the test. -// If the transaction is not of type InvokeTxnV1, it fails the test. Finally, it asserts +// If the transaction is not of type InvokeTxn3, it fails the test. Finally, it asserts // that the transaction type is TransactionType_Invoke and that the transaction is equal to the expected transaction. // // Parameters: @@ -118,28 +95,70 @@ func TestTransactionByBlockIdAndIndex(t *testing.T) { ExpectedTxn Transaction } - var InvokeTxnV1example = InvokeTxnV1{ + var InvokeTxnV3example = InvokeTxnV3{ Type: TransactionType_Invoke, - MaxFee: utils.TestHexToFelt(t, "0x53685de02fa5"), - Version: TransactionV1, - Nonce: &felt.Zero, + Version: TransactionV3, + Nonce: utils.TestHexToFelt(t, "0x359d"), Signature: []*felt.Felt{ - utils.TestHexToFelt(t, "0x4a7849de7b91e52cd0cdaf4f40aa67f54a58e25a15c60e034d2be819c1ecda4"), - utils.TestHexToFelt(t, "0x227fcad2a0007348e64384649365e06d41287b1887999b406389ee73c1d8c4c"), + utils.TestHexToFelt(t, "0x665f0c67ed4d9565f63857b1a55974b98b2411f579c53c9f903fd21a3edb3d1"), + utils.TestHexToFelt(t, "0x549c4480aba4753c58f757c92b5a1d3d67b2ced4bf06076825af3f52f738d6d"), + }, + SenderAddress: utils.TestHexToFelt(t, "0x143fe26927dd6a302522ea1cd6a821ab06b3753194acee38d88a85c93b3cbc6"), + NonceDataMode: DAModeL1, + FeeMode: DAModeL1, + PayMasterData: []*felt.Felt{}, + AccountDeploymentData: []*felt.Felt{}, + ResourceBounds: ResourceBoundsMapping{ + L1Gas: ResourceBounds{ + MaxAmount: "0x3bb2", + MaxPricePerUnit: "0x2ba7def30000", + }, + L2Gas: ResourceBounds{ + MaxAmount: "0x0", + MaxPricePerUnit: "0x0", + }, }, - SenderAddress: utils.TestHexToFelt(t, "0x315e364b162653e5c7b23efd34f8da27ba9c069b68e3042b7d76ce1df890313"), Calldata: []*felt.Felt{ utils.TestHexToFelt(t, "0x1"), - utils.TestHexToFelt(t, "0x13befe6eda920ce4af05a50a67bd808d67eee6ba47bb0892bef2d630eaf1bba"), + utils.TestHexToFelt(t, "0x6b74c515944ef1ef630ee1cf08a22e110c39e217fa15554a089182a11f78ed"), + utils.TestHexToFelt(t, "0xc844fd57777b0cd7e75c8ea68deec0adf964a6308da7a58de32364b7131cc8"), + utils.TestHexToFelt(t, "0x13"), + utils.TestHexToFelt(t, "0x41bbf1eff2ac123d9e01004a385329369cbc1c309838562f030b3faa2caa4"), + utils.TestHexToFelt(t, "0x54103"), + utils.TestHexToFelt(t, "0x7e430a7a59836b5969859b25379c640a8ccb66fb142606d7acb1a5563c2ad9"), + utils.TestHexToFelt(t, "0x6600d829"), + utils.TestHexToFelt(t, "0x103020400000000000000000000000000000000000000000000000000000000"), + utils.TestHexToFelt(t, "0x4"), + utils.TestHexToFelt(t, "0x5f5e100"), + utils.TestHexToFelt(t, "0x5f60fc2"), + utils.TestHexToFelt(t, "0x5f60fc2"), + utils.TestHexToFelt(t, "0x5f6570d"), + utils.TestHexToFelt(t, "0xa07695b6574c60c37"), + utils.TestHexToFelt(t, "0x1"), + utils.TestHexToFelt(t, "0x2"), + utils.TestHexToFelt(t, "0x7afe11c6cdf846e8e33ff55c6e8310293b81aa58da4618af0c2fb29db2515c7"), + utils.TestHexToFelt(t, "0x1200966b0f9a5cd1bf7217b202c3a4073a1ff583e4779a3a3ffb97a532fe0c"), + utils.TestHexToFelt(t, "0x2cb74dff29a13dd5d855159349ec92f943bacf0547ff3734e7d84a15d08cbc5"), + utils.TestHexToFelt(t, "0x460769330eab4b3269a5c07369382fcc09fbfc92458c63f77292425c72272f9"), + utils.TestHexToFelt(t, "0x10ebdb197fd1017254b927b01073c64a368db45534413b539895768e57b72ba"), + utils.TestHexToFelt(t, "0x2e7dc996ebf724c1cf18d668fc3455df4245749ebc0724101cbc6c9cb13c962"), }, + Tip: "0x0", } testSet := map[string][]testSetType{ "mock": { { - BlockID: WithBlockNumber(300000), + BlockID: WithBlockHash(utils.TestHexToFelt(t, "0x4ae5d52c75e4dea5694f456069f830cfbc7bec70427eee170c3385f751b8564")), Index: 0, - ExpectedTxn: InvokeTxnV1example, + ExpectedTxn: InvokeTxnV3example, + }, + }, + "testnet": { + { + BlockID: WithBlockHash(utils.TestHexToFelt(t, "0x4ae5d52c75e4dea5694f456069f830cfbc7bec70427eee170c3385f751b8564")), + Index: 15, + ExpectedTxn: InvokeTxnV3example, }, }, "mainnet": {}, @@ -154,10 +173,11 @@ func TestTransactionByBlockIdAndIndex(t *testing.T) { if tx == nil { t.Fatal("transaction should exist") } - txCasted, ok := (tx).(InvokeTxnV1) + txCasted, ok := (tx).(InvokeTxnV3) if !ok { - t.Fatalf("transaction should be InvokeTxnV1, instead %T", tx) + t.Fatalf("transaction should be InvokeTxnV3, instead %T", tx) } + require.Equal(t, txCasted.Type, TransactionType_Invoke) require.Equal(t, txCasted, test.ExpectedTxn) } @@ -170,116 +190,88 @@ func TestTransactionReceipt(t *testing.T) { TxnHash *felt.Felt ExpectedResp TransactionReceiptWithBlockInfo } - var receiptTxn310370_0 = InvokeTransactionReceipt(CommonTransactionReceipt{ - TransactionHash: utils.TestHexToFelt(t, "0x40c82f79dd2bc1953fc9b347a3e7ab40fe218ed5740bf4e120f74e8a3c9ac99"), - ActualFee: FeePayment{Amount: utils.TestHexToFelt(t, "0x1709a2f3a2"), Unit: UnitWei}, + var receiptTxn52767_16 = InvokeTransactionReceipt(CommonTransactionReceipt{ + TransactionHash: utils.TestHexToFelt(t, "0xf2f3d50192637e8d5e817363460c39d3a668fe12f117ecedb9749466d8352b"), + ActualFee: FeePayment{ + Amount: utils.TestHexToFelt(t, "0x16409a78a10b00"), + Unit: UnitStrk, + }, Type: "INVOKE", ExecutionStatus: TxnExecutionStatusSUCCEEDED, FinalityStatus: TxnFinalityStatusAcceptedOnL1, MessagesSent: []MsgToL1{}, Events: []Event{ { - FromAddress: utils.TestHexToFelt(t, "0x37de00fb1416936b3074fc78bcc811d83046009b162c4a822ce84dabedd0ea9"), Data: []*felt.Felt{ - utils.TestHexToFelt(t, "0x0"), - utils.TestHexToFelt(t, "0x35b32bb4a1969175fb14b6c09838d1b3200724cc4d2b0891be319764021f5ac"), - utils.TestHexToFelt(t, "0xe9"), - utils.TestHexToFelt(t, "0x0"), + utils.TestHexToFelt(t, "0x3028044a4c4df95c0b0a907307c6feffa76b9c38e83088ade29b186a250eb13"), + utils.TestHexToFelt(t, "0x3"), + utils.TestHexToFelt(t, "0x17a393a5e943cec833c8a8f4cbbf7c58361fb2fdd9caa0c36d901eedec4938e"), + utils.TestHexToFelt(t, "0x776731d30bd922ac0390edfc664ed31b232aa7c7ce389c333e34c6b32957532"), + utils.TestHexToFelt(t, "0x40851db0ebaebb9f8a18eda25005c050793f2a69e9e7d1f44bc133752898918"), }, - Keys: []*felt.Felt{utils.TestHexToFelt(t, "0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9")}, - }, - { - FromAddress: utils.TestHexToFelt(t, "0x33830ce413e4c096eef81b5e6ffa9b9f5d963f57b8cd63c9ae4c839c383c1a6"), - Data: []*felt.Felt{ - utils.TestHexToFelt(t, "0x61c6e7484657e5dc8b21677ffa33e4406c0600bba06d12cf1048fdaa55bdbc3"), - utils.TestHexToFelt(t, "0x2e28403d7ee5e337b7d456327433f003aa875c29631906908900058c83d8cb6"), + FromAddress: utils.TestHexToFelt(t, "0x243d436e1f7cea085aaa42834975488029b1ebf67cea1d2e86f7de58e7d34a3"), + Keys: []*felt.Felt{ + utils.TestHexToFelt(t, "0x15bd0500dc9d7e69ab9577f73a8d753e8761bed10f25ba0f124254dc4edb8b4"), }, - Keys: []*felt.Felt{utils.TestHexToFelt(t, "0xf806f71b19e4744968b37e3fb288e61309ab33a782ea9d11e18f67a1fbb110")}, - }, - }, - ExecutionResources: ExecutionResources{ - ComputationResources: ComputationResources{ - Steps: 217182, - MemoryHoles: 6644, - PedersenApps: 2142, - RangeCheckApps: 8867, - BitwiseApps: 900, - ECDSAApps: 1, }, - }, - }) - - var receiptTxnIntegration = InvokeTransactionReceipt(CommonTransactionReceipt{ - TransactionHash: utils.TestHexToFelt(t, "0x49728601e0bb2f48ce506b0cbd9c0e2a9e50d95858aa41463f46386dca489fd"), - ActualFee: FeePayment{Amount: utils.TestHexToFelt(t, "0x16d8b4ad4000"), Unit: UnitStrk}, - Type: "INVOKE", - ExecutionStatus: TxnExecutionStatusSUCCEEDED, - FinalityStatus: TxnFinalityStatusAcceptedOnL2, - MessagesSent: []MsgToL1{}, - Events: []Event{ { - FromAddress: utils.TestHexToFelt(t, "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"), Data: []*felt.Felt{ - utils.TestHexToFelt(t, "0x3f6f3bc663aedc5285d6013cc3ffcbc4341d86ab488b8b68d297f8258793c41"), + utils.TestHexToFelt(t, "0x6016d919abf2ddefe03dacc2ff5c8f42eb80cf65add1e90dd73c5c5e06ef3e2"), utils.TestHexToFelt(t, "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"), - utils.TestHexToFelt(t, "0x16d8b4ad4000"), + utils.TestHexToFelt(t, "0x16409a78a10b00"), utils.TestHexToFelt(t, "0x0"), }, - Keys: []*felt.Felt{utils.TestHexToFelt(t, "0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9")}, - }, - { FromAddress: utils.TestHexToFelt(t, "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"), - Data: []*felt.Felt{ - utils.TestHexToFelt(t, "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"), - utils.TestHexToFelt(t, "0x18ad8494375bc00"), - utils.TestHexToFelt(t, "0x0"), - utils.TestHexToFelt(t, "0x18aef21f822fc00"), - utils.TestHexToFelt(t, "0x0"), + Keys: []*felt.Felt{ + utils.TestHexToFelt(t, "0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9"), }, - Keys: []*felt.Felt{utils.TestHexToFelt(t, "0xa9fa878c35cd3d0191318f89033ca3e5501a3d90e21e3cc9256bdd5cd17fdd")}, }, }, ExecutionResources: ExecutionResources{ ComputationResources: ComputationResources{ - Steps: 615, - MemoryHoles: 4, - RangeCheckApps: 19, + Steps: 5774, + PedersenApps: 24, + ECOPApps: 3, + RangeCheckApps: 152, + }, + DataAvailability: DataAvailability{ + L1Gas: 0, + L1DataGas: 0, }, }, }) testSet := map[string][]testSetType{ - "mock": {}, - "testnet": { + "mock": { { - TxnHash: utils.TestHexToFelt(t, "0x40c82f79dd2bc1953fc9b347a3e7ab40fe218ed5740bf4e120f74e8a3c9ac99"), + TxnHash: utils.TestHexToFelt(t, "0xf2f3d50192637e8d5e817363460c39d3a668fe12f117ecedb9749466d8352b"), ExpectedResp: TransactionReceiptWithBlockInfo{ - TransactionReceipt: receiptTxn310370_0, - BlockNumber: 310370, - BlockHash: utils.TestHexToFelt(t, "0x6c2fe3db009a2e008c2d65fca14204f3405cb74742fcf685f02473acaf70c72"), + UnknownTransactionReceipt: UnknownTransactionReceipt{receiptTxn52767_16}, + BlockNumber: 52767, + BlockHash: utils.TestHexToFelt(t, "0x4ae5d52c75e4dea5694f456069f830cfbc7bec70427eee170c3385f751b8564"), }, }, }, - "mainnet": {}, - "integration": { + "testnet": { { - TxnHash: utils.TestHexToFelt(t, "0x49728601e0bb2f48ce506b0cbd9c0e2a9e50d95858aa41463f46386dca489fd"), + TxnHash: utils.TestHexToFelt(t, "0xf2f3d50192637e8d5e817363460c39d3a668fe12f117ecedb9749466d8352b"), ExpectedResp: TransactionReceiptWithBlockInfo{ - TransactionReceipt: receiptTxnIntegration, - BlockNumber: 319132, - BlockHash: utils.TestHexToFelt(t, "0x50e864db6b81ce69fbeb70e6a7284ee2febbb9a2e707415de7adab83525e9cd"), + UnknownTransactionReceipt: UnknownTransactionReceipt{receiptTxn52767_16}, + BlockNumber: 52767, + BlockHash: utils.TestHexToFelt(t, "0x4ae5d52c75e4dea5694f456069f830cfbc7bec70427eee170c3385f751b8564"), }, }, - }}[testEnv] + }, + "mainnet": {}, + "integration": {}, + }[testEnv] for _, test := range testSet { spy := NewSpy(testConfig.provider.c) testConfig.provider.c = spy txReceiptWithBlockInfo, err := testConfig.provider.TransactionReceipt(context.Background(), test.TxnHash) require.Nil(t, err) - require.Equal(t, txReceiptWithBlockInfo.BlockNumber, test.ExpectedResp.BlockNumber) - require.Equal(t, txReceiptWithBlockInfo.BlockHash, test.ExpectedResp.BlockHash) - + require.Equal(t, test.ExpectedResp, *txReceiptWithBlockInfo) } } @@ -296,7 +288,7 @@ func TestGetTransactionStatus(t *testing.T) { "mock": {}, "testnet": { { - TxnHash: utils.TestHexToFelt(t, "0x46a9f52a96b2d226407929e04cb02507e531f7c78b9196fc8c910351d8c33f3"), + TxnHash: utils.TestHexToFelt(t, "0xd109474cd037bad60a87ba0ccf3023d5f2d1cd45220c62091d41a614d38eda"), ExpectedResp: TxnStatusResp{FinalityStatus: TxnStatus_Accepted_On_L1, ExecutionStatus: TxnExecutionStatusSUCCEEDED}, }, }, diff --git a/rpc/types_block_transaction.go b/rpc/types_block_transaction.go index df08bd07..7eb7cd24 100644 --- a/rpc/types_block_transaction.go +++ b/rpc/types_block_transaction.go @@ -16,105 +16,61 @@ 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{} // Hash returns the transaction hash of the BlockInvokeTxnV0. -// -// Parameters: -// -// none -// -// Returns: -// - *felt.Felt: the transaction hash func (tx BlockInvokeTxnV0) Hash() *felt.Felt { return tx.TransactionHash } // Hash returns the hash of the BlockInvokeTxnV1 transaction. -// -// Parameters: -// -// none -// -// Returns: -// - *felt.Felt: the transaction hash func (tx BlockInvokeTxnV1) Hash() *felt.Felt { return tx.TransactionHash } +// Hash returns the hash of the BlockInvokeTxnV3 transaction. +func (tx BlockInvokeTxnV3) Hash() *felt.Felt { + return tx.TransactionHash +} + // Hash returns the transaction hash of the BlockDeclareTxnV0. -// -// Parameters: -// -// none -// -// Returns: -// - *felt.Felt: the transaction hash func (tx BlockDeclareTxnV0) Hash() *felt.Felt { return tx.TransactionHash } // Hash returns the transaction hash of the BlockDeclareTxnV1. -// -// Parameters: -// -// none -// -// Returns: -// - *felt.Felt: the transaction hash func (tx BlockDeclareTxnV1) Hash() *felt.Felt { return tx.TransactionHash } // Hash returns the transaction hash of the BlockDeclareTxnV2. -// -// Parameters: -// -// none -// -// Returns: -// - *felt.Felt: the transaction hash func (tx BlockDeclareTxnV2) Hash() *felt.Felt { return tx.TransactionHash } +// Hash returns the transaction hash of the BlockDeclareTxnV3. +func (tx BlockDeclareTxnV3) Hash() *felt.Felt { + return tx.TransactionHash +} + // Hash returns the hash of the BlockDeployTxn. -// -// Parameters: -// -// none -// -// Returns: -// - *felt.Felt: the transaction hash func (tx BlockDeployTxn) Hash() *felt.Felt { return tx.TransactionHash } // Hash returns the Felt hash of the BlockDeployAccountTxn. -// -// Parameters: -// -// none -// -// Returns: -// - *felt.Felt: the transaction hash func (tx BlockDeployAccountTxn) Hash() *felt.Felt { return tx.TransactionHash } // Hash returns the hash of the BlockL1HandlerTxn. -// -// Parameters: -// -// none -// -// Returns: -// - *felt.Felt: the transaction hash func (tx BlockL1HandlerTxn) Hash() *felt.Felt { return tx.TransactionHash } @@ -129,6 +85,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 +110,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 +179,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 @@ -229,10 +199,14 @@ func unmarshalBlockTxn(t interface{}) (BlockTransaction, error) { var txn BlockInvokeTxnV0 err := remarshal(casted, &txn) return txn, err - } else { + } else if casted["version"].(string) == "0x1" { var txn BlockInvokeTxnV1 err := remarshal(casted, &txn) return txn, err + } else { + var txn BlockInvokeTxnV3 + err := remarshal(casted, &txn) + return txn, err } case TransactionType_L1Handler: var txn BlockL1HandlerTxn diff --git a/rpc/types_transaction.go b/rpc/types_transaction.go index 624d911e..8420fe60 100644 --- a/rpc/types_transaction.go +++ b/rpc/types_transaction.go @@ -13,20 +13,26 @@ import ( // https://github.com/starkware-libs/starknet-specs/blob/a789ccc3432c57777beceaa53a34a7ae2f25fda0/api/starknet_api_openrpc.json#L1252 type TXN struct { - Hash *felt.Felt `json:"transaction_hash,omitempty"` - Type TransactionType `json:"type"` - Version *felt.Felt `json:"version,omitempty"` - Nonce *felt.Felt `json:"nonce,omitempty"` - MaxFee *felt.Felt `json:"max_fee,omitempty"` - ContractAddress *felt.Felt `json:"contract_address,omitempty"` - ContractAddressSalt *felt.Felt `json:"contract_address_salt,omitempty"` - ClassHash *felt.Felt `json:"class_hash,omitempty"` - ConstructorCalldata []*felt.Felt `json:"constructor_calldata,omitempty"` - SenderAddress *felt.Felt `json:"sender_address,omitempty"` - Signature *[]*felt.Felt `json:"signature,omitempty"` - Calldata *[]*felt.Felt `json:"calldata,omitempty"` - EntryPointSelector *felt.Felt `json:"entry_point_selector,omitempty"` - CompiledClassHash *felt.Felt `json:"compiled_class_hash,omitempty"` + Hash *felt.Felt `json:"transaction_hash,omitempty"` + Type TransactionType `json:"type"` + Version *felt.Felt `json:"version,omitempty"` + Nonce *felt.Felt `json:"nonce,omitempty"` + MaxFee *felt.Felt `json:"max_fee,omitempty"` + ContractAddress *felt.Felt `json:"contract_address,omitempty"` + ContractAddressSalt *felt.Felt `json:"contract_address_salt,omitempty"` + ClassHash *felt.Felt `json:"class_hash,omitempty"` + ConstructorCalldata []*felt.Felt `json:"constructor_calldata,omitempty"` + SenderAddress *felt.Felt `json:"sender_address,omitempty"` + Signature *[]*felt.Felt `json:"signature,omitempty"` + Calldata *[]*felt.Felt `json:"calldata,omitempty"` + EntryPointSelector *felt.Felt `json:"entry_point_selector,omitempty"` + CompiledClassHash *felt.Felt `json:"compiled_class_hash,omitempty"` + ResourceBounds ResourceBoundsMapping `json:"resource_bounds"` + Tip U64 `json:"tip"` + PayMasterData []*felt.Felt `json:"paymaster_data"` + AccountDeploymentData []*felt.Felt `json:"account_deployment_data"` + NonceDataMode DataAvailabilityMode `json:"nonce_data_availability_mode"` + FeeMode DataAvailabilityMode `json:"fee_data_availability_mode"` } type InvokeTxnV0 struct { @@ -156,7 +162,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 diff --git a/rpc/types_transaction_receipt.go b/rpc/types_transaction_receipt.go index 9e06f0b0..d65fa54c 100644 --- a/rpc/types_transaction_receipt.go +++ b/rpc/types_transaction_receipt.go @@ -38,25 +38,10 @@ type CommonTransactionReceipt struct { } // Hash returns the transaction hash associated with the CommonTransactionReceipt. -// -// Parameters: -// -// none -// -// Returns: -// - *felt.Felt: the transaction hash func (tr CommonTransactionReceipt) Hash() *felt.Felt { return tr.TransactionHash } -// GetExecutionStatus returns the execution status of the CommonTransactionReceipt. -// -// Parameters: -// -// none -// -// Returns: -// - TxnExecutionStatus: the execution status func (tr CommonTransactionReceipt) GetExecutionStatus() TxnExecutionStatus { return tr.ExecutionStatus } @@ -116,10 +101,6 @@ func (tt *TransactionType) UnmarshalJSON(data []byte) error { // MarshalJSON marshals the TransactionType to JSON. // -// Parameters: -// -// none -// // Returns: // - []byte: a byte slice // - error: an error if any @@ -131,25 +112,11 @@ func (tt TransactionType) MarshalJSON() ([]byte, error) { type InvokeTransactionReceipt CommonTransactionReceipt // Hash returns the hash of the invoke transaction receipt. -// -// Parameters: -// -// none -// -// Returns: -// - *felt.Felt: the transaction hash func (tr InvokeTransactionReceipt) Hash() *felt.Felt { return tr.TransactionHash } // GetExecutionStatus returns the execution status of the InvokeTransactionReceipt. -// -// Parameters: -// -// none -// -// Returns: -// - TxnExecutionStatus: the execution status func (tr InvokeTransactionReceipt) GetExecutionStatus() TxnExecutionStatus { return tr.ExecutionStatus } @@ -158,25 +125,11 @@ func (tr InvokeTransactionReceipt) GetExecutionStatus() TxnExecutionStatus { type DeclareTransactionReceipt CommonTransactionReceipt // Hash returns the transaction hash. -// -// Parameters: -// -// none -// -// Returns: -// - *felt.Felt: the transaction hash func (tr DeclareTransactionReceipt) Hash() *felt.Felt { return tr.TransactionHash } // GetExecutionStatus returns the execution status of the DeclareTransactionReceipt function. -// -// Parameters: -// -// none -// -// Returns: -// - TxnExecutionStatus: the execution status func (tr DeclareTransactionReceipt) GetExecutionStatus() TxnExecutionStatus { return tr.ExecutionStatus } @@ -189,25 +142,11 @@ type DeployTransactionReceipt struct { } // Hash returns the transaction hash of the DeployTransactionReceipt. -// -// Parameters: -// -// none -// -// Returns: -// - *felt.Felt: the transaction hash func (tr DeployTransactionReceipt) Hash() *felt.Felt { return tr.TransactionHash } // GetExecutionStatus returns the execution status of the DeployTransactionReceipt. -// -// Parameters: -// -// none -// -// Returns: -// - TxnExecutionStatus: the execution status func (tr DeployTransactionReceipt) GetExecutionStatus() TxnExecutionStatus { return tr.ExecutionStatus } @@ -220,25 +159,11 @@ type DeployAccountTransactionReceipt struct { } // Hash returns the transaction hash for the given DeployAccountTransactionReceipt. -// -// Parameters: -// -// none -// -// Returns: -// - *felt.Felt: the transaction hash func (tr DeployAccountTransactionReceipt) Hash() *felt.Felt { return tr.TransactionHash } // GetExecutionStatus returns the execution status of the DeployAccountTransactionReceipt. -// -// Parameters: -// -// none -// -// Returns: -// - *TxnExecutionStatus: the execution status func (tr DeployAccountTransactionReceipt) GetExecutionStatus() TxnExecutionStatus { return tr.ExecutionStatus } @@ -247,25 +172,11 @@ func (tr DeployAccountTransactionReceipt) GetExecutionStatus() TxnExecutionStatu type L1HandlerTransactionReceipt CommonTransactionReceipt // Hash returns the transaction hash. -// -// Parameters: -// -// none -// -// Returns: -// - *felt.Felt: the transaction hash func (tr L1HandlerTransactionReceipt) Hash() *felt.Felt { return tr.TransactionHash } // GetExecutionStatus returns the execution status of the L1HandlerTransactionReceipt. -// -// Parameters: -// -// none -// -// Returns: -// - TxnExecutionStatus: the execution status func (tr L1HandlerTransactionReceipt) GetExecutionStatus() TxnExecutionStatus { return tr.ExecutionStatus } @@ -366,8 +277,11 @@ func (tr *UnknownTransactionReceipt) UnmarshalJSON(data []byte) error { if err != nil { return err } - - t, err := unmarshalTransactionReceipt(dec) + bytes, err := json.Marshal(dec) + if err != nil { + return err + } + t, err := unmarshalTransactionReceipt(bytes) if err != nil { return err } @@ -382,43 +296,47 @@ func (tr *UnknownTransactionReceipt) UnmarshalJSON(data []byte) error { // Returns: // - TransactionReceipt: a TransactionReceipt // - error: an error if the unmarshaling fails -func unmarshalTransactionReceipt(t interface{}) (TransactionReceipt, error) { - switch casted := t.(type) { - case map[string]interface{}: - // NOTE(tvanas): Pathfinder 0.3.3 does not return - // transaction receipt types. We handle this by - // naively marshalling into an invoke type. Once it - // is supported, this condition can be removed. - typ, ok := casted["type"] - if !ok { - return nil, fmt.Errorf("unknown transaction type: %v", t) - } - - switch TransactionType(typ.(string)) { - case TransactionType_Invoke: - var txn InvokeTransactionReceipt - err := remarshal(casted, &txn) - return txn, err - case TransactionType_L1Handler: - var txn L1HandlerTransactionReceipt - err := remarshal(casted, &txn) - return txn, err - case TransactionType_Declare: - var txn DeclareTransactionReceipt - err := remarshal(casted, &txn) - return txn, err - case TransactionType_Deploy: - var txn DeployTransactionReceipt - err := remarshal(casted, &txn) - return txn, err - case TransactionType_DeployAccount: - var txn DeployAccountTransactionReceipt - err := remarshal(casted, &txn) - return txn, err - } +func unmarshalTransactionReceipt(data []byte) (TransactionReceipt, error) { + + var dec map[string]interface{} + if err := json.Unmarshal(data, &dec); err != nil { + return nil, err + } + + typ, ok := dec["type"] + if !ok { + return nil, fmt.Errorf("unknown transaction type: %v", typ) } - return nil, fmt.Errorf("unknown transaction type: %v", t) + jsonData, err := json.Marshal(dec) + if err != nil { + return nil, err + } + + switch TransactionType(typ.(string)) { + case TransactionType_Invoke: + var txn InvokeTransactionReceipt + err := json.Unmarshal(jsonData, &txn) + return txn, err + case TransactionType_L1Handler: + var txn L1HandlerTransactionReceipt + err := json.Unmarshal(jsonData, &txn) + return txn, err + case TransactionType_Declare: + var txn DeclareTransactionReceipt + err := json.Unmarshal(jsonData, &txn) + return txn, err + case TransactionType_Deploy: + var txn DeployTransactionReceipt + err := json.Unmarshal(jsonData, &txn) + return txn, err + case TransactionType_DeployAccount: + var txn DeployAccountTransactionReceipt + err := json.Unmarshal(jsonData, &txn) + return txn, err + } + + return nil, fmt.Errorf("unknown transaction type: %v", typ) } // The finality status of the transaction, including the case the txn is still in the mempool or failed validation during the block construction phase @@ -437,7 +355,48 @@ type TxnStatusResp struct { } type TransactionReceiptWithBlockInfo struct { - TransactionReceipt + UnknownTransactionReceipt BlockHash *felt.Felt `json:"block_hash,omitempty"` BlockNumber uint `json:"block_number,omitempty"` } + +func (t *TransactionReceiptWithBlockInfo) UnmarshalJSON(data []byte) error { + var uTxnRec UnknownTransactionReceipt + err := uTxnRec.UnmarshalJSON(data) + if err != nil { + return err + } + t.UnknownTransactionReceipt = uTxnRec + + aux := &struct { + BlockHash string `json:"block_hash,omitempty"` + BlockNumber uint `json:"block_number,omitempty"` + }{} + + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + blockHash, err := new(felt.Felt).SetString(aux.BlockHash) + if err != nil { + return err + } + + t.BlockHash = blockHash + t.BlockNumber = aux.BlockNumber + + return nil +} + +func (t *TransactionReceiptWithBlockInfo) MarshalJSON() ([]byte, error) { + aux := &struct { + TransactionReceipt + BlockHash string `json:"block_hash,omitempty"` + BlockNumber uint `json:"block_number,omitempty"` + }{ + TransactionReceipt: t.UnknownTransactionReceipt.TransactionReceipt, + BlockHash: t.BlockHash.String(), + BlockNumber: t.BlockNumber, + } + + return json.Marshal(aux) +}