diff --git a/README.md b/README.md index 5a151521..fd995e9c 100644 --- a/README.md +++ b/README.md @@ -92,10 +92,11 @@ go run main.go ### RPC -`starknet.go` RPC implements the [Starknet RPC v0.6.0 spec](https://github.com/starkware-libs/starknet-specs/tree/v0.6.0): +`starknet.go` RPC implements the Starknet [RPC v0.7.0 spec](https://github.com/starkware-libs/starknet-specs/tree/v0.7.0-rc2) | Method | Implemented (*) | | ------------------------------------------ | ------------------ | +| `starknet_getBlockWithReceipts` | :heavy_check_mark: | | `starknet_getBlockWithTxHashes` | :heavy_check_mark: | | `starknet_getBlockWithTxs` | :heavy_check_mark: | | `starknet_getStateUpdate` | :heavy_check_mark: | diff --git a/account/account.go b/account/account.go index fb0a1a4d..c0716f0b 100644 --- a/account/account.go +++ b/account/account.go @@ -37,7 +37,7 @@ type AccountInterface interface { SignDeployAccountTransaction(ctx context.Context, tx *rpc.DeployAccountTxn, precomputeAddress *felt.Felt) error SignDeclareTransaction(ctx context.Context, tx *rpc.DeclareTxnV2) error PrecomputeAddress(deployerAddress *felt.Felt, salt *felt.Felt, classHash *felt.Felt, constructorCalldata []*felt.Felt) (*felt.Felt, error) - WaitForTransactionReceipt(ctx context.Context, transactionHash *felt.Felt, pollInterval time.Duration) (*rpc.TransactionReceipt, *rpc.RPCError) + WaitForTransactionReceipt(ctx context.Context, transactionHash *felt.Felt, pollInterval time.Duration) (*rpc.TransactionReceiptWithBlockInfo, *rpc.RPCError) } var _ AccountInterface = &Account{} @@ -525,14 +525,14 @@ func (account *Account) PrecomputeAddress(deployerAddress *felt.Felt, salt *felt // It returns: // - *rpc.TransactionReceipt: the transaction receipt // - error: an error -func (account *Account) WaitForTransactionReceipt(ctx context.Context, transactionHash *felt.Felt, pollInterval time.Duration) (*rpc.TransactionReceipt, *rpc.RPCError) { +func (account *Account) WaitForTransactionReceipt(ctx context.Context, transactionHash *felt.Felt, pollInterval time.Duration) (*rpc.TransactionReceiptWithBlockInfo, *rpc.RPCError) { t := time.NewTicker(pollInterval) for { select { case <-ctx.Done(): return nil, rpc.Err(rpc.InternalError, ctx.Err()) case <-t.C: - receipt, rpcErr := account.TransactionReceipt(ctx, transactionHash) + receiptWithBlockInfo, rpcErr := account.TransactionReceipt(ctx, transactionHash) if rpcErr != nil { if rpcErr.Message == rpc.ErrHashNotFound.Message { continue @@ -540,7 +540,7 @@ func (account *Account) WaitForTransactionReceipt(ctx context.Context, transacti return nil, rpcErr } } - return &receipt, nil + return receiptWithBlockInfo, nil } } } @@ -839,7 +839,7 @@ func (account *Account) TraceBlockTransactions(ctx context.Context, blockID rpc. // - transactionHash: The hash of the transaction. // Returns: // - rpc.Transactiontype: rpc.TransactionReceipt, error. -func (account *Account) TransactionReceipt(ctx context.Context, transactionHash *felt.Felt) (rpc.TransactionReceipt, *rpc.RPCError) { +func (account *Account) TransactionReceipt(ctx context.Context, transactionHash *felt.Felt) (*rpc.TransactionReceiptWithBlockInfo, *rpc.RPCError) { return account.provider.TransactionReceipt(ctx, transactionHash) } diff --git a/account/account_test.go b/account/account_test.go index 3f48816e..50cbeffe 100644 --- a/account/account_test.go +++ b/account/account_test.go @@ -949,7 +949,7 @@ func TestWaitForTransactionReceiptMOCK(t *testing.T) { ShouldCallTransactionReceipt bool Hash *felt.Felt ExpectedErr *rpc.RPCError - ExpectedReceipt rpc.TransactionReceipt + ExpectedReceipt *rpc.TransactionReceiptWithBlockInfo } testSet := map[string][]testSetType{ "mock": { @@ -964,10 +964,13 @@ func TestWaitForTransactionReceiptMOCK(t *testing.T) { Timeout: time.Duration(1000), Hash: new(felt.Felt).SetUint64(2), ShouldCallTransactionReceipt: true, - ExpectedReceipt: rpc.InvokeTransactionReceipt{ - TransactionHash: new(felt.Felt).SetUint64(2), - ExecutionStatus: rpc.TxnExecutionStatusSUCCEEDED, + ExpectedReceipt: &rpc.TransactionReceiptWithBlockInfo{ + TransactionReceipt: rpc.InvokeTransactionReceipt{ + TransactionHash: new(felt.Felt).SetUint64(2), + ExecutionStatus: rpc.TxnExecutionStatusSUCCEEDED, + }, }, + ExpectedErr: nil, }, { @@ -991,7 +994,7 @@ func TestWaitForTransactionReceiptMOCK(t *testing.T) { if test.ExpectedErr != nil { require.Equal(t, test.ExpectedErr, err) } else { - require.Equal(t, test.ExpectedReceipt.GetExecutionStatus(), (*resp).GetExecutionStatus()) + require.Equal(t, test.ExpectedReceipt.GetExecutionStatus(), (resp.TransactionReceipt).GetExecutionStatus()) } } diff --git a/mocks/mock_rpc_provider.go b/mocks/mock_rpc_provider.go index 7f9182ea..1285a893 100644 --- a/mocks/mock_rpc_provider.go +++ b/mocks/mock_rpc_provider.go @@ -462,10 +462,10 @@ func (mr *MockRpcProviderMockRecorder) TransactionByHash(ctx, hash any) *gomock. } // TransactionReceipt mocks base method. -func (m *MockRpcProvider) TransactionReceipt(ctx context.Context, transactionHash *felt.Felt) (rpc.TransactionReceipt, *rpc.RPCError) { +func (m *MockRpcProvider) TransactionReceipt(ctx context.Context, transactionHash *felt.Felt) (*rpc.TransactionReceiptWithBlockInfo, *rpc.RPCError) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "TransactionReceipt", ctx, transactionHash) - ret0, _ := ret[0].(rpc.TransactionReceipt) + ret0, _ := ret[0].(*rpc.TransactionReceiptWithBlockInfo) ret1, _ := ret[1].(*rpc.RPCError) return ret0, ret1 } diff --git a/rpc/mock_test.go b/rpc/mock_test.go index 34b42c48..13e64334 100644 --- a/rpc/mock_test.go +++ b/rpc/mock_test.go @@ -326,14 +326,36 @@ func mock_starknet_getTransactionReceipt(result interface{}, method string, args return errWrongArgs } - arg0Felt, err := utils.HexToFelt(args[0].(string)) + arg0Felt := args[0].(*felt.Felt) + + testTxnHash, err := utils.HexToFelt("0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e") if err != nil { return err } + if arg0Felt.Equal(testTxnHash) { + var txnRec struct { + Result UnknownTransactionReceipt `json:"result"` + } + read, err := os.ReadFile("tests/receipt/0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e.json") + if err != nil { + return err + } + err = json.Unmarshal(read, &txnRec) + if err != nil { + return err + } + txnReceipt, err := json.Marshal(txnRec.Result.TransactionReceipt) + if err != nil { + return err + } + return json.Unmarshal(txnReceipt, &r) + } + fromAddressFelt, err := utils.HexToFelt("0xdeadbeef") if err != nil { return err } + transaction := InvokeTransactionReceipt(CommonTransactionReceipt{ TransactionHash: arg0Felt, FinalityStatus: TxnFinalityStatusAcceptedOnL1, @@ -1095,11 +1117,11 @@ func mock_starknet_traceTransaction(result interface{}, method string, args ...i return errors.Wrap(errWrongArgs, fmt.Sprintf("args[0] should be felt, got %T\n", args[0])) } switch transactionHash.String() { - case "0xff66e14fc6a96f3289203690f5f876cb4b608868e8549b5f6a90a21d4d6329": + case "0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e": var rawTrace struct { Result InvokeTxnTrace `json:"result"` } - read, err := os.ReadFile("tests/trace/0xff66e14fc6a96f3289203690f5f876cb4b608868e8549b5f6a90a21d4d6329.json") + read, err := os.ReadFile("tests/trace/0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e.json") if err != nil { return err } diff --git a/rpc/provider.go b/rpc/provider.go index 5181f5b4..5b73d910 100644 --- a/rpc/provider.go +++ b/rpc/provider.go @@ -67,7 +67,7 @@ type RpcProvider interface { TraceBlockTransactions(ctx context.Context, blockID BlockID) ([]Trace, *RPCError) TransactionByBlockIdAndIndex(ctx context.Context, blockID BlockID, index uint64) (Transaction, *RPCError) TransactionByHash(ctx context.Context, hash *felt.Felt) (Transaction, *RPCError) - TransactionReceipt(ctx context.Context, transactionHash *felt.Felt) (TransactionReceipt, *RPCError) + TransactionReceipt(ctx context.Context, transactionHash *felt.Felt) (*TransactionReceiptWithBlockInfo, *RPCError) TraceTransaction(ctx context.Context, transactionHash *felt.Felt) (TxnTrace, *RPCError) } diff --git a/rpc/tests/receipt/0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e.json b/rpc/tests/receipt/0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e.json new file mode 100644 index 00000000..9a7fc8d7 --- /dev/null +++ b/rpc/tests/receipt/0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e.json @@ -0,0 +1,54 @@ +{ + "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/trace/0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e.json b/rpc/tests/trace/0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e.json new file mode 100644 index 00000000..d27a3588 --- /dev/null +++ b/rpc/tests/trace/0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e.json @@ -0,0 +1,245 @@ +{ + "jsonrpc": "2.0", + "result": { + "type": "INVOKE", + "validate_invocation": { + "contract_address": "0x14c5c28581c68f64c9a3d86b919094a5209fe0ccb454f776b3be2c3968cd91d", + "entry_point_selector": "0x162da33a4585851fe8d3af3c2a9c60b557814e221e0d4f30ff0b2189d9c7775", + "calldata": [ + "0x1", + "0x232438a37dc1e45f6cf278b308db7d1868016a5a6a2f6c4d3da746b4d13d891", + "0x19a35a6e95cb7a3318dbb244f20975a1cd8587cc6b5259f15f61d7beb7ee43b", + "0x2", + "0x3b73e1773ce95172c5f525f29d4d1eb2b407429559bceaa7dec815deb6c0028", + "0x29a82e0d28fd72bfbafa6bb5cdffd9cdb00bf2145f0542d2de771fe640b49ba" + ], + "caller_address": "0x0", + "class_hash": "0x55c0c1e3c04fb72c602d62e1c9d2c07bf2932cb8cb0d72f210fa259272a1e21", + "entry_point_type": "EXTERNAL", + "call_type": "CALL", + "result": [ + "0x56414c4944" + ], + "calls": [], + "events": [], + "messages": [], + "execution_resources": { + "steps": 675, + "memory_holes": 41, + "range_check_builtin_applications": 22, + "ec_op_builtin_applications": 3 + } + }, + "execute_invocation": { + "contract_address": "0x14c5c28581c68f64c9a3d86b919094a5209fe0ccb454f776b3be2c3968cd91d", + "entry_point_selector": "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad", + "calldata": [ + "0x1", + "0x232438a37dc1e45f6cf278b308db7d1868016a5a6a2f6c4d3da746b4d13d891", + "0x19a35a6e95cb7a3318dbb244f20975a1cd8587cc6b5259f15f61d7beb7ee43b", + "0x2", + "0x3b73e1773ce95172c5f525f29d4d1eb2b407429559bceaa7dec815deb6c0028", + "0x29a82e0d28fd72bfbafa6bb5cdffd9cdb00bf2145f0542d2de771fe640b49ba" + ], + "caller_address": "0x0", + "class_hash": "0x55c0c1e3c04fb72c602d62e1c9d2c07bf2932cb8cb0d72f210fa259272a1e21", + "entry_point_type": "EXTERNAL", + "call_type": "CALL", + "result": [ + "0x1", + "0x0" + ], + "calls": [ + { + "contract_address": "0x232438a37dc1e45f6cf278b308db7d1868016a5a6a2f6c4d3da746b4d13d891", + "entry_point_selector": "0x19a35a6e95cb7a3318dbb244f20975a1cd8587cc6b5259f15f61d7beb7ee43b", + "calldata": [ + "0x3b73e1773ce95172c5f525f29d4d1eb2b407429559bceaa7dec815deb6c0028", + "0x29a82e0d28fd72bfbafa6bb5cdffd9cdb00bf2145f0542d2de771fe640b49ba" + ], + "caller_address": "0x14c5c28581c68f64c9a3d86b919094a5209fe0ccb454f776b3be2c3968cd91d", + "class_hash": "0x3ae2f9b340e70e3c6ae2101715ccde645f3766283bd3bfade4b5ce7cd7dc9c6", + "entry_point_type": "EXTERNAL", + "call_type": "CALL", + "result": [], + "calls": [ + { + "contract_address": "0x3b73e1773ce95172c5f525f29d4d1eb2b407429559bceaa7dec815deb6c0028", + "entry_point_selector": "0x3d7905601c217734671143d457f0db37f7f8883112abd34b92c4abfeafde0c3", + "calldata": [ + "0x29a82e0d28fd72bfbafa6bb5cdffd9cdb00bf2145f0542d2de771fe640b49ba", + "0x7e5" + ], + "caller_address": "0x232438a37dc1e45f6cf278b308db7d1868016a5a6a2f6c4d3da746b4d13d891", + "class_hash": "0x3ae2f9b340e70e3c6ae2101715ccde645f3766283bd3bfade4b5ce7cd7dc9c6", + "entry_point_type": "EXTERNAL", + "call_type": "CALL", + "result": [], + "calls": [], + "events": [], + "messages": [], + "execution_resources": { + "steps": 115, + "range_check_builtin_applications": 1 + } + }, + { + "contract_address": "0x3b73e1773ce95172c5f525f29d4d1eb2b407429559bceaa7dec815deb6c0028", + "entry_point_selector": "0x26813d396fdb198e9ead934e4f7a592a8b88a059e45ab0eb6ee53494e8d45b0", + "calldata": [ + "0x29a82e0d28fd72bfbafa6bb5cdffd9cdb00bf2145f0542d2de771fe640b49ba" + ], + "caller_address": "0x232438a37dc1e45f6cf278b308db7d1868016a5a6a2f6c4d3da746b4d13d891", + "class_hash": "0x3ae2f9b340e70e3c6ae2101715ccde645f3766283bd3bfade4b5ce7cd7dc9c6", + "entry_point_type": "EXTERNAL", + "call_type": "CALL", + "result": [ + "0x7e5" + ], + "calls": [], + "events": [], + "messages": [], + "execution_resources": { + "steps": 119, + "range_check_builtin_applications": 1 + } + } + ], + "events": [], + "messages": [], + "execution_resources": { + "steps": 2045, + "range_check_builtin_applications": 44 + } + } + ], + "events": [], + "messages": [], + "execution_resources": { + "steps": 3433, + "memory_holes": 11, + "range_check_builtin_applications": 83 + } + }, + "fee_transfer_invocation": { + "contract_address": "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d", + "entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e", + "calldata": [ + "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8", + "0x30df144f446a59", + "0x0" + ], + "caller_address": "0x14c5c28581c68f64c9a3d86b919094a5209fe0ccb454f776b3be2c3968cd91d", + "class_hash": "0x6e7226605869c2bd8cb86a647b451adc0b90e1e4f00b1c45d502dcd2ba6d41e", + "entry_point_type": "EXTERNAL", + "call_type": "CALL", + "result": [ + "0x1" + ], + "calls": [], + "events": [ + { + "order": 0, + "keys": [ + "0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9", + "0x14c5c28581c68f64c9a3d86b919094a5209fe0ccb454f776b3be2c3968cd91d", + "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8" + ], + "data": [ + "0x30df144f446a59", + "0x0" + ] + }, + { + "order": 1, + "keys": [ + "0xa9fa878c35cd3d0191318f89033ca3e5501a3d90e21e3cc9256bdd5cd17fdd" + ], + "data": [ + "0xca46d96b37266650e0a8b79938d9300037337cad82ea4f45a921ad68b6a5f9", + "0x477bd3017f2b1cec6", + "0x0", + "0x477ee0f2c41f6391f", + "0x0" + ] + } + ], + "messages": [], + "execution_resources": { + "steps": 4876, + "memory_holes": 135, + "pedersen_builtin_applications": 7, + "range_check_builtin_applications": 140, + "bitwise_builtin_applications": 4, + "poseidon_builtin_applications": 3 + } + }, + "state_diff": { + "storage_diffs": [ + { + "address": "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d", + "storage_entries": [ + { + "key": "0x5496768776e3db30053404f18067d81a6e06f5a2b0de326e21298fd9d569a9a", + "value": "0x477ee0f2c41f6391f" + }, + { + "key": "0x2752ca5adc5b7283939990e78f0c2ad01c3394a4f0029df0de0cdaf8843e326", + "value": "0x2cb7" + }, + { + "key": "0x726c8bbcf545d8f818f9af08edb856c3039ed29ade3ac61ffc0114734c2b265", + "value": "0x65e81e0500000000000000000000000000000477ee0f2c41f6391f" + }, + { + "key": "0x21894759e00509af176c850d579cc207ffe30b1abcb72dd930c819a0244de20", + "value": "0x219c829e117bbd8e9d1" + } + ] + }, + { + "address": "0x3b73e1773ce95172c5f525f29d4d1eb2b407429559bceaa7dec815deb6c0028", + "storage_entries": [ + { + "key": "0x29a82e0d28fd72bfbafa6bb5cdffd9cdb00bf2145f0542d2de771fe640b49ba", + "value": "0x7e5" + } + ] + }, + { + "address": "0x232438a37dc1e45f6cf278b308db7d1868016a5a6a2f6c4d3da746b4d13d891", + "storage_entries": [ + { + "key": "0x29a82e0d28fd72bfbafa6bb5cdffd9cdb00bf2145f0542d2de771fe640b49ba", + "value": "0x7c7" + } + ] + } + ], + "nonces": [ + { + "contract_address": "0x14c5c28581c68f64c9a3d86b919094a5209fe0ccb454f776b3be2c3968cd91d", + "nonce": "0x2aee" + } + ], + "deployed_contracts": [], + "deprecated_declared_classes": [], + "declared_classes": [], + "replaced_classes": [] + }, + "execution_resources": { + "steps": 8984, + "memory_holes": 187, + "pedersen_builtin_applications": 7, + "range_check_builtin_applications": 245, + "bitwise_builtin_applications": 4, + "ec_op_builtin_applications": 3, + "poseidon_builtin_applications": 3, + "data_availability": { + "l1_gas": 21, + "l1_data_gas": 384 + } + } + }, + "id": 1 +} \ No newline at end of file diff --git a/rpc/tests/trace/0xff66e14fc6a96f3289203690f5f876cb4b608868e8549b5f6a90a21d4d6329.json b/rpc/tests/trace/0xff66e14fc6a96f3289203690f5f876cb4b608868e8549b5f6a90a21d4d6329.json deleted file mode 100644 index 5d6ae2c8..00000000 --- a/rpc/tests/trace/0xff66e14fc6a96f3289203690f5f876cb4b608868e8549b5f6a90a21d4d6329.json +++ /dev/null @@ -1,582 +0,0 @@ -{ - "jsonrpc": "2.0", - "result": { - "validate_invocation": { - "contract_address": "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516", - "entry_point_selector": "0x162da33a4585851fe8d3af3c2a9c60b557814e221e0d4f30ff0b2189d9c7775", - "calldata": [ - "0x2", - "0x22b05f9396d2c48183f6deaf138a57522bcc8b35b67dee919f76403d1783136", - "0x219209e083275171774dab1df80982e9df2096516f06319c5c6d71ae0a8480c", - "0x0", - "0x3", - "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "0xb69b4361a8bcfea4e074bd844f59471180e9e07bd42a66ff4906186a9f2628", - "0x3", - "0x7", - "0xa", - "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "0x17520d3a", - "0x0", - "0x1", - "0x17520d3a", - "0x0", - "0xd27007cc0c3", - "0x0", - "0x5c29", - "0x0" - ], - "caller_address": "0x0", - "class_hash": "0x25ec026985a3bf9d0cc1fe17326b245dfdc3ff89b8fde106542a3ea56c5a918", - "entry_point_type": "EXTERNAL", - "call_type": "CALL", - "result": [], - "calls": [ - { - "contract_address": "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516", - "entry_point_selector": "0x162da33a4585851fe8d3af3c2a9c60b557814e221e0d4f30ff0b2189d9c7775", - "calldata": [ - "0x2", - "0x22b05f9396d2c48183f6deaf138a57522bcc8b35b67dee919f76403d1783136", - "0x219209e083275171774dab1df80982e9df2096516f06319c5c6d71ae0a8480c", - "0x0", - "0x3", - "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "0xb69b4361a8bcfea4e074bd844f59471180e9e07bd42a66ff4906186a9f2628", - "0x3", - "0x7", - "0xa", - "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "0x17520d3a", - "0x0", - "0x1", - "0x17520d3a", - "0x0", - "0xd27007cc0c3", - "0x0", - "0x5c29", - "0x0" - ], - "caller_address": "0x0", - "class_hash": "0x33434ad846cdd5f23eb73ff09fe6fddd568284a0fb7d1be20ee482f044dabe2", - "entry_point_type": "EXTERNAL", - "call_type": "LIBRARY_CALL", - "result": [], - "calls": [], - "events": [], - "messages": [] - } - ], - "events": [], - "messages": [] - }, - "execute_invocation": { - "contract_address": "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516", - "entry_point_selector": "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad", - "calldata": [ - "0x2", - "0x22b05f9396d2c48183f6deaf138a57522bcc8b35b67dee919f76403d1783136", - "0x219209e083275171774dab1df80982e9df2096516f06319c5c6d71ae0a8480c", - "0x0", - "0x3", - "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "0xb69b4361a8bcfea4e074bd844f59471180e9e07bd42a66ff4906186a9f2628", - "0x3", - "0x7", - "0xa", - "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "0x17520d3a", - "0x0", - "0x1", - "0x17520d3a", - "0x0", - "0xd27007cc0c3", - "0x0", - "0x5c29", - "0x0" - ], - "caller_address": "0x0", - "class_hash": "0x25ec026985a3bf9d0cc1fe17326b245dfdc3ff89b8fde106542a3ea56c5a918", - "entry_point_type": "EXTERNAL", - "call_type": "CALL", - "result": [ - "0x1", - "0xd633b2913ee", - "0x0", - "0x5e47", - "0x0", - "0x4477606da4ac2b7bef", - "0x0", - "0x1e226129b7e", - "0x0" - ], - "calls": [ - { - "contract_address": "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516", - "entry_point_selector": "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad", - "calldata": [ - "0x2", - "0x22b05f9396d2c48183f6deaf138a57522bcc8b35b67dee919f76403d1783136", - "0x219209e083275171774dab1df80982e9df2096516f06319c5c6d71ae0a8480c", - "0x0", - "0x3", - "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "0xb69b4361a8bcfea4e074bd844f59471180e9e07bd42a66ff4906186a9f2628", - "0x3", - "0x7", - "0xa", - "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "0x17520d3a", - "0x0", - "0x1", - "0x17520d3a", - "0x0", - "0xd27007cc0c3", - "0x0", - "0x5c29", - "0x0" - ], - "caller_address": "0x0", - "class_hash": "0x33434ad846cdd5f23eb73ff09fe6fddd568284a0fb7d1be20ee482f044dabe2", - "entry_point_type": "EXTERNAL", - "call_type": "LIBRARY_CALL", - "result": [ - "0x1", - "0xd633b2913ee", - "0x0", - "0x5e47", - "0x0", - "0x4477606da4ac2b7bef", - "0x0", - "0x1e226129b7e", - "0x0" - ], - "calls": [ - { - "contract_address": "0x22b05f9396d2c48183f6deaf138a57522bcc8b35b67dee919f76403d1783136", - "entry_point_selector": "0x219209e083275171774dab1df80982e9df2096516f06319c5c6d71ae0a8480c", - "calldata": [ - "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "0x17520d3a", - "0x0" - ], - "caller_address": "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516", - "class_hash": "0x2797c4997ea0ca14401188bf6cbd4d89f0e632bd088088ab6cabf63c2056fc8", - "entry_point_type": "EXTERNAL", - "call_type": "CALL", - "result": [ - "0x1" - ], - "calls": [], - "events": [ - { - "order": 0, - "keys": [ - "0x134692b230b9e1ffa39098904722134159652b09c5bc41d88d6698779d228ff" - ], - "data": [ - "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516", - "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "0x17520d3a", - "0x0" - ] - } - ], - "messages": [] - }, - { - "contract_address": "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "entry_point_selector": "0xb69b4361a8bcfea4e074bd844f59471180e9e07bd42a66ff4906186a9f2628", - "calldata": [ - "0x1", - "0x17520d3a", - "0x0", - "0xd27007cc0c3", - "0x0", - "0x5c29", - "0x0" - ], - "caller_address": "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516", - "class_hash": "0x7e35b811e3d4e2678d037b632a0c8a09a46d82185187762c0d429363e3ef9cf", - "entry_point_type": "EXTERNAL", - "call_type": "CALL", - "result": [ - "0xd633b2913ee", - "0x0", - "0x5e47", - "0x0", - "0x4477606da4ac2b7bef", - "0x0", - "0x1e226129b7e", - "0x0" - ], - "calls": [ - { - "contract_address": "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "entry_point_selector": "0xb69b4361a8bcfea4e074bd844f59471180e9e07bd42a66ff4906186a9f2628", - "calldata": [ - "0x1", - "0x17520d3a", - "0x0", - "0xd27007cc0c3", - "0x0", - "0x5c29", - "0x0" - ], - "caller_address": "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516", - "class_hash": "0x55ef1b2cb1313b8202f68ef32aaefca4133b21cbce68c4bfee453e595ce646f", - "entry_point_type": "EXTERNAL", - "call_type": "LIBRARY_CALL", - "result": [ - "0xd633b2913ee", - "0x0", - "0x5e47", - "0x0", - "0x4477606da4ac2b7bef", - "0x0", - "0x1e226129b7e", - "0x0" - ], - "calls": [ - { - "contract_address": "0x22b05f9396d2c48183f6deaf138a57522bcc8b35b67dee919f76403d1783136", - "entry_point_selector": "0x80aa9fdbfaf9615e4afc7f5f722e265daca5ccc655360fa5ccacf9c267936d", - "calldata": [], - "caller_address": "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "class_hash": "0x2797c4997ea0ca14401188bf6cbd4d89f0e632bd088088ab6cabf63c2056fc8", - "entry_point_type": "EXTERNAL", - "call_type": "CALL", - "result": [ - "0x7743beb1ef9ce8", - "0x0" - ], - "calls": [], - "events": [], - "messages": [] - }, - { - "contract_address": "0x22b05f9396d2c48183f6deaf138a57522bcc8b35b67dee919f76403d1783136", - "entry_point_selector": "0x2e4263afad30923c891518314c3c95dbe830a16874e8abc5777a9a20b54c76e", - "calldata": [ - "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516" - ], - "caller_address": "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "class_hash": "0x2797c4997ea0ca14401188bf6cbd4d89f0e632bd088088ab6cabf63c2056fc8", - "entry_point_type": "EXTERNAL", - "call_type": "CALL", - "result": [ - "0x7a6ec573", - "0x0" - ], - "calls": [], - "events": [], - "messages": [] - }, - { - "contract_address": "0x22b05f9396d2c48183f6deaf138a57522bcc8b35b67dee919f76403d1783136", - "entry_point_selector": "0x35528e7a5a578129b17edda3b942aff94e6191011372bc35bf3d31dcbb2614b", - "calldata": [ - "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516", - "0x17520d3a", - "0x0" - ], - "caller_address": "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "class_hash": "0x2797c4997ea0ca14401188bf6cbd4d89f0e632bd088088ab6cabf63c2056fc8", - "entry_point_type": "EXTERNAL", - "call_type": "CALL", - "result": [], - "calls": [], - "events": [ - { - "order": 1, - "keys": [ - "0x134692b230b9e1ffa39098904722134159652b09c5bc41d88d6698779d228ff" - ], - "data": [ - "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516", - "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "0x0", - "0x0" - ] - }, - { - "order": 2, - "keys": [ - "0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9" - ], - "data": [ - "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516", - "0x0", - "0x17520d3a", - "0x0" - ] - } - ], - "messages": [] - }, - { - "contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7", - "entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e", - "calldata": [ - "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516", - "0xd633b2913ee", - "0x0" - ], - "caller_address": "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "class_hash": "0xd0e183745e9dae3e4e78a8ffedcce0903fc4900beace4e0abf192d4c202da3", - "entry_point_type": "EXTERNAL", - "call_type": "CALL", - "result": [ - "0x1" - ], - "calls": [ - { - "contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7", - "entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e", - "calldata": [ - "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516", - "0xd633b2913ee", - "0x0" - ], - "caller_address": "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "class_hash": "0x2760f25d5a4fb2bdde5f561fd0b44a3dee78c28903577d37d669939d97036a0", - "entry_point_type": "EXTERNAL", - "call_type": "LIBRARY_CALL", - "result": [ - "0x1" - ], - "calls": [], - "events": [ - { - "order": 3, - "keys": [ - "0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9" - ], - "data": [ - "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516", - "0xd633b2913ee", - "0x0" - ] - } - ], - "messages": [] - } - ], - "events": [], - "messages": [] - }, - { - "contract_address": "0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8", - "entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e", - "calldata": [ - "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516", - "0x5e47", - "0x0" - ], - "caller_address": "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "class_hash": "0x52c7ba99c77fc38dd3346beea6c0753c3471f2e3135af5bb837d6c9523fff62", - "entry_point_type": "EXTERNAL", - "call_type": "CALL", - "result": [ - "0x1" - ], - "calls": [ - { - "contract_address": "0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8", - "entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e", - "calldata": [ - "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516", - "0x5e47", - "0x0" - ], - "caller_address": "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "class_hash": "0x2760f25d5a4fb2bdde5f561fd0b44a3dee78c28903577d37d669939d97036a0", - "entry_point_type": "EXTERNAL", - "call_type": "LIBRARY_CALL", - "result": [ - "0x1" - ], - "calls": [], - "events": [ - { - "order": 4, - "keys": [ - "0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9" - ], - "data": [ - "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516", - "0x5e47", - "0x0" - ] - } - ], - "messages": [] - } - ], - "events": [], - "messages": [] - } - ], - "events": [], - "messages": [] - } - ], - "events": [], - "messages": [] - } - ], - "events": [ - { - "order": 5, - "keys": [ - "0x5ad857f66a5b55f1301ff1ed7e098ac6d4433148f0b72ebc4a2945ab85ad53" - ], - "data": [ - "0xff66e14fc6a96f3289203690f5f876cb4b608868e8549b5f6a90a21d4d6329", - "0x9", - "0x1", - "0xd633b2913ee", - "0x0", - "0x5e47", - "0x0", - "0x4477606da4ac2b7bef", - "0x0", - "0x1e226129b7e", - "0x0" - ] - } - ], - "messages": [] - } - ], - "events": [], - "messages": [] - }, - "fee_transfer_invocation": { - "contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7", - "entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e", - "calldata": [ - "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8", - "0x9aaea1158c19", - "0x0" - ], - "caller_address": "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516", - "class_hash": "0xd0e183745e9dae3e4e78a8ffedcce0903fc4900beace4e0abf192d4c202da3", - "entry_point_type": "EXTERNAL", - "call_type": "CALL", - "result": [ - "0x1" - ], - "calls": [ - { - "contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7", - "entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e", - "calldata": [ - "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8", - "0x9aaea1158c19", - "0x0" - ], - "caller_address": "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516", - "class_hash": "0x2760f25d5a4fb2bdde5f561fd0b44a3dee78c28903577d37d669939d97036a0", - "entry_point_type": "EXTERNAL", - "call_type": "LIBRARY_CALL", - "result": [ - "0x1" - ], - "calls": [], - "events": [ - { - "order": 0, - "keys": [ - "0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9" - ], - "data": [ - "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516", - "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8", - "0x9aaea1158c19", - "0x0" - ] - } - ], - "messages": [] - } - ], - "events": [], - "messages": [] - }, - "type": "INVOKE", - "state_diff": { - "storage_diffs": [ - { - "address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7", - "storage_entries": [ - { - "key": "0x49a8ef79cab313360767015d427d0307368eff5c2c81b019aff018ec638eef2", - "value": "0x763b821506b19086e9" - }, - { - "key": "0x625da4622cb73a56b1f10ac489e48b4e8af830a368fb3e21db8b7868c315ff0", - "value": "0x19094ba60d592b" - }, - { - "key": "0x5496768776e3db30053404f18067d81a6e06f5a2b0de326e21298fd9d569a9a", - "value": "0x11e93b002a1d5c717d" - } - ] - }, - { - "address": "0x10884171baf1914edc28d7afb619b40a4051cfae78a094a55d230f19e944a28", - "storage_entries": [ - { - "key": "0x2487f67598912d31ab84d8fa97c9e78332d00795ecdad092ea09f9c9c14a9a3", - "value": "0x1e226129b7e" - }, - { - "key": "0x2487f67598912d31ab84d8fa97c9e78332d00795ecdad092ea09f9c9c14a9a0", - "value": "0x4477606da4ac2b7bef" - } - ] - }, - { - "address": "0x22b05f9396d2c48183f6deaf138a57522bcc8b35b67dee919f76403d1783136", - "storage_entries": [ - { - "key": "0x110e2f729c9c2b988559994a3daccd838cf52faf88e18101373e67dd061455a", - "value": "0x7743be9a9d8fae" - }, - { - "key": "0x625da4622cb73a56b1f10ac489e48b4e8af830a368fb3e21db8b7868c315ff0", - "value": "0x631cb839" - } - ] - }, - { - "address": "0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8", - "storage_entries": [ - { - "key": "0x625da4622cb73a56b1f10ac489e48b4e8af830a368fb3e21db8b7868c315ff0", - "value": "0x17fc5" - }, - { - "key": "0x49a8ef79cab313360767015d427d0307368eff5c2c81b019aff018ec638eef2", - "value": "0x257875e1c11" - } - ] - } - ], - "nonces": [ - { - "contract_address": "0x61d862eb8baf0dc8e14159d0dd16abcff933c798ecf252ce81685d74c237516", - "nonce": "0x58" - } - ], - "deployed_contracts": [], - "deprecated_declared_classes": [], - "declared_classes": [], - "replaced_classes": [] - } - }, - "id": 1 -} \ No newline at end of file diff --git a/rpc/trace_test.go b/rpc/trace_test.go index 8044efcc..cb1da7d5 100644 --- a/rpc/trace_test.go +++ b/rpc/trace_test.go @@ -30,7 +30,7 @@ func TestTransactionTrace(t *testing.T) { var rawjson struct { Result InvokeTxnTrace `json:"result"` } - expectedrespRaw, err := os.ReadFile("./tests/trace/0xff66e14fc6a96f3289203690f5f876cb4b608868e8549b5f6a90a21d4d6329.json") + expectedrespRaw, err := os.ReadFile("./tests/trace/0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e.json") require.NoError(t, err, "Error ReadFile for TestTraceTransaction") err = json.Unmarshal(expectedrespRaw, &rawjson) @@ -43,14 +43,14 @@ func TestTransactionTrace(t *testing.T) { type testSetType struct { TransactionHash *felt.Felt - ExpectedResp TxnTrace + ExpectedResp *InvokeTxnTrace ExpectedError *RPCError } testSet := map[string][]testSetType{ "mock": { testSetType{ - TransactionHash: utils.TestHexToFelt(t, "0xff66e14fc6a96f3289203690f5f876cb4b608868e8549b5f6a90a21d4d6329"), - ExpectedResp: expectedResp, + TransactionHash: utils.TestHexToFelt(t, "0x4b861c47d0fbc4cc24dacf92cf155ad0a2f7e2a0fd9b057b90cdd64eba7e12e"), + ExpectedResp: &expectedResp, ExpectedError: nil, }, testSetType{ @@ -77,7 +77,8 @@ func TestTransactionTrace(t *testing.T) { if err != nil { require.Equal(t, test.ExpectedError, err) } else { - require.Equal(t, test.ExpectedResp, resp) + invokeTrace := resp.(InvokeTxnTrace) + require.Equal(t, invokeTrace, *test.ExpectedResp) } } } diff --git a/rpc/transaction.go b/rpc/transaction.go index caefe654..1517a428 100644 --- a/rpc/transaction.go +++ b/rpc/transaction.go @@ -107,13 +107,13 @@ func (provider *Provider) TransactionByBlockIdAndIndex(ctx context.Context, bloc // Returns: // - TransactionReceipt: the transaction receipt // - error: an error if any -func (provider *Provider) TransactionReceipt(ctx context.Context, transactionHash *felt.Felt) (TransactionReceipt, *RPCError) { - var receipt UnknownTransactionReceipt +func (provider *Provider) TransactionReceipt(ctx context.Context, transactionHash *felt.Felt) (*TransactionReceiptWithBlockInfo, *RPCError) { + var receipt TransactionReceiptWithBlockInfo err := do(ctx, provider.c, "starknet_getTransactionReceipt", &receipt, transactionHash) if err != nil { return nil, tryUnwrapToRPCErr(err, ErrHashNotFound) } - return receipt.TransactionReceipt, nil + return &receipt, nil } // GetTransactionStatus gets the transaction status (possibly reflecting that the tx is still in the mempool, or dropped from it) diff --git a/rpc/transaction_test.go b/rpc/transaction_test.go index 4d5814f4..765bb553 100644 --- a/rpc/transaction_test.go +++ b/rpc/transaction_test.go @@ -2,12 +2,10 @@ package rpc import ( "context" - "regexp" "testing" "github.com/NethermindEth/juno/core/felt" "github.com/NethermindEth/starknet.go/utils" - "github.com/google/go-cmp/cmp" "github.com/test-go/testify/require" ) @@ -165,19 +163,12 @@ func TestTransactionByBlockIdAndIndex(t *testing.T) { } } -// TestTransactionReceipt_MatchesCapturedTransaction tests if the transaction receipt matches the captured transaction. -// -// Parameters: -// - t: the testing object for running the test cases -// Returns: -// -// none -func TestTransactionReceipt_MatchesCapturedTransaction(t *testing.T) { +func TestTransactionReceipt(t *testing.T) { testConfig := beforeEach(t) type testSetType struct { - TxnHash *felt.Felt - ExpectedTxnReceipt TransactionReceipt + TxnHash *felt.Felt + ExpectedResp TransactionReceiptWithBlockInfo } var receiptTxn310370_0 = InvokeTransactionReceipt(CommonTransactionReceipt{ TransactionHash: utils.TestHexToFelt(t, "0x40c82f79dd2bc1953fc9b347a3e7ab40fe218ed5740bf4e120f74e8a3c9ac99"), @@ -185,8 +176,6 @@ func TestTransactionReceipt_MatchesCapturedTransaction(t *testing.T) { Type: "INVOKE", ExecutionStatus: TxnExecutionStatusSUCCEEDED, FinalityStatus: TxnFinalityStatusAcceptedOnL1, - BlockHash: utils.TestHexToFelt(t, "0x6c2fe3db009a2e008c2d65fca14204f3405cb74742fcf685f02473acaf70c72"), - BlockNumber: 310370, MessagesSent: []MsgToL1{}, Events: []Event{ { @@ -209,12 +198,14 @@ func TestTransactionReceipt_MatchesCapturedTransaction(t *testing.T) { }, }, ExecutionResources: ExecutionResources{ - Steps: 217182, - MemoryHoles: 6644, - PedersenApps: 2142, - RangeCheckApps: 8867, - BitwiseApps: 900, - ECDSAApps: 1, + ComputationResources: ComputationResources{ + Steps: 217182, + MemoryHoles: 6644, + PedersenApps: 2142, + RangeCheckApps: 8867, + BitwiseApps: 900, + ECDSAApps: 1, + }, }, }) @@ -224,8 +215,6 @@ func TestTransactionReceipt_MatchesCapturedTransaction(t *testing.T) { Type: "INVOKE", ExecutionStatus: TxnExecutionStatusSUCCEEDED, FinalityStatus: TxnFinalityStatusAcceptedOnL2, - BlockHash: utils.TestHexToFelt(t, "0x50e864db6b81ce69fbeb70e6a7284ee2febbb9a2e707415de7adab83525e9cd"), - BlockNumber: 319132, MessagesSent: []MsgToL1{}, Events: []Event{ { @@ -251,9 +240,11 @@ func TestTransactionReceipt_MatchesCapturedTransaction(t *testing.T) { }, }, ExecutionResources: ExecutionResources{ - Steps: 615, - MemoryHoles: 4, - RangeCheckApps: 19, + ComputationResources: ComputationResources{ + Steps: 615, + MemoryHoles: 4, + RangeCheckApps: 19, + }, }, }) @@ -261,154 +252,33 @@ func TestTransactionReceipt_MatchesCapturedTransaction(t *testing.T) { "mock": {}, "testnet": { { - TxnHash: utils.TestHexToFelt(t, "0x40c82f79dd2bc1953fc9b347a3e7ab40fe218ed5740bf4e120f74e8a3c9ac99"), - ExpectedTxnReceipt: receiptTxn310370_0, + TxnHash: utils.TestHexToFelt(t, "0x40c82f79dd2bc1953fc9b347a3e7ab40fe218ed5740bf4e120f74e8a3c9ac99"), + ExpectedResp: TransactionReceiptWithBlockInfo{ + TransactionReceipt: receiptTxn310370_0, + BlockNumber: 310370, + BlockHash: utils.TestHexToFelt(t, "0x6c2fe3db009a2e008c2d65fca14204f3405cb74742fcf685f02473acaf70c72"), + }, }, }, "mainnet": {}, "integration": { { - TxnHash: utils.TestHexToFelt(t, "0x49728601e0bb2f48ce506b0cbd9c0e2a9e50d95858aa41463f46386dca489fd"), - ExpectedTxnReceipt: receiptTxnIntegration, + TxnHash: utils.TestHexToFelt(t, "0x49728601e0bb2f48ce506b0cbd9c0e2a9e50d95858aa41463f46386dca489fd"), + ExpectedResp: TransactionReceiptWithBlockInfo{ + TransactionReceipt: receiptTxnIntegration, + BlockNumber: 319132, + BlockHash: utils.TestHexToFelt(t, "0x50e864db6b81ce69fbeb70e6a7284ee2febbb9a2e707415de7adab83525e9cd"), + }, }, }}[testEnv] for _, test := range testSet { spy := NewSpy(testConfig.provider.c) testConfig.provider.c = spy - txReceiptInterface, err := testConfig.provider.TransactionReceipt(context.Background(), test.TxnHash) - if err != nil { - t.Fatal(err) - } - - if txReceiptInterface == nil { - t.Fatal("transaction receipt should exist") - } - txnReceipt, ok := txReceiptInterface.(InvokeTransactionReceipt) - if !ok { - t.Fatalf("transaction receipt should be InvokeTransactionReceipt, instead %T", txReceiptInterface) - } - if !cmp.Equal(test.ExpectedTxnReceipt, txnReceipt) { - t.Fatalf("the expected transaction blocks to match, instead: %s", cmp.Diff(test.ExpectedTxnReceipt, txnReceipt)) - } - } -} - -// TestTransactionReceipt_MatchesStatus tests if the transaction receipt matches the given execution status. -// -// It initializes a test configuration and defines a test set containing transaction hash and execution status pairs. -// For each test in the test set, it creates a spy and sets the provider of the test configuration to the spy. -// Then, it retrieves the transaction receipt for the given transaction hash using the provider. -// If the transaction receipt does not exist, it fails the test. -// It asserts that the transaction receipt is of type InvokeTransactionReceipt. -// Finally, it checks if the execution status of the transaction receipt matches the expected execution status using a regular expression. -// -// Parameters: -// - t: the testing object for running the test cases -// Returns: -// -// none -func TestTransactionReceipt_MatchesStatus(t *testing.T) { - testConfig := beforeEach(t) - - type testSetType struct { - TxnHash *felt.Felt - ExecutionStatus string - } - testSet := map[string][]testSetType{ - "mock": {}, - "testnet": { - { - TxnHash: utils.TestHexToFelt(t, "0x650667fb0f17e63e1c9d1040e750d160f3dbfebcab990e7d4382f33468b1b59"), - ExecutionStatus: "(SUCCEEDED|REVERTED)", - }, - }, - "mainnet": {}, - }[testEnv] - - for _, test := range testSet { - spy := NewSpy(testConfig.provider.c, false) - testConfig.provider.c = spy - txReceiptInterface, err := testConfig.provider.TransactionReceipt(context.Background(), test.TxnHash) - if err != nil { - t.Fatal(err) - } - if txReceiptInterface == nil { - t.Fatal("transaction receipt should exist") - } - txnReceipt, ok := txReceiptInterface.(InvokeTransactionReceipt) - if !ok { - t.Fatalf("transaction receipt should be InvokeTransactionReceipt, instead %T", txReceiptInterface) - } - if ok, err := regexp.MatchString(test.ExecutionStatus, string(txnReceipt.ExecutionStatus)); err != nil || !ok { - t.Fatal("error checking transaction status", ok, err, txnReceipt.ExecutionStatus) - } - } -} - -// TestDeployOrDeclareReceipt is a test function that verifies the functionality of the DeployOrDeclareReceipt method. -// -// It tests the behavior of the DeployOrDeclareReceipt method by creating a test configuration, defining a test set, -// and executing the test set for the specified test environment. It makes assertions to ensure that the expected -// transaction receipt matches the actual transaction receipt returned by the method. -// -// The function takes no parameters and does not return any values. -// -// Parameters: -// - t: the testing object for running the test cases -// Returns: -// -// none -func TestDeployOrDeclareReceipt(t *testing.T) { - testConfig := beforeEach(t) - - type testSetType struct { - TxnHash *felt.Felt - ExpectedTxnReceipt TransactionReceipt - } - - var receiptTxn300114_3 = DeclareTransactionReceipt( - CommonTransactionReceipt{ - TransactionHash: utils.TestHexToFelt(t, "0x46a9f52a96b2d226407929e04cb02507e531f7c78b9196fc8c910351d8c33f3"), - ActualFee: FeePayment{Amount: utils.TestHexToFelt(t, "0x0"), Unit: UnitWei}, - FinalityStatus: TxnFinalityStatusAcceptedOnL1, - ExecutionStatus: TxnExecutionStatusSUCCEEDED, - BlockHash: utils.TestHexToFelt(t, "0x184268bfbce24766fa53b65c9c8b30b295e145e8281d543a015b46308e27fdf"), - BlockNumber: 300114, - Type: "DECLARE", - MessagesSent: []MsgToL1{}, - Events: []Event{}, - ExecutionResources: ExecutionResources{Steps: 0}, - }) - - testSet := map[string][]testSetType{ - "mock": {}, - "testnet": { - { - TxnHash: utils.TestHexToFelt(t, "0x46a9f52a96b2d226407929e04cb02507e531f7c78b9196fc8c910351d8c33f3"), - ExpectedTxnReceipt: receiptTxn300114_3, - }, - }, - "mainnet": {}, - }[testEnv] - - for _, test := range testSet { - spy := NewSpy(testConfig.provider.c) - testConfig.provider.c = spy - txReceiptInterface, err := testConfig.provider.TransactionReceipt(context.Background(), test.TxnHash) - if err != nil { - t.Fatal(err) - } - if txReceiptInterface == nil { - t.Fatal("transaction receipt should exist") - } - txnDeclareReceipt, ok := txReceiptInterface.(DeclareTransactionReceipt) - if !ok { - t.Fatalf("transaction receipt should be Deploy or Declare, instead %T", txReceiptInterface) - } - if !cmp.Equal(test.ExpectedTxnReceipt, txnDeclareReceipt) { - t.Fatalf("the expected transaction blocks to match, instead: %s", cmp.Diff(test.ExpectedTxnReceipt, txnDeclareReceipt)) - } + 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) } } @@ -435,7 +305,7 @@ func TestGetTransactionStatus(t *testing.T) { for _, test := range testSet { resp, err := testConfig.provider.GetTransactionStatus(context.Background(), test.TxnHash) - require.NoError(t, err) + require.Nil(t, err) require.Equal(t, *resp, test.ExpectedResp) } } diff --git a/rpc/types_trace.go b/rpc/types_trace.go index ad78299e..95b172fd 100644 --- a/rpc/types_trace.go +++ b/rpc/types_trace.go @@ -39,28 +39,31 @@ var _ TxnTrace = L1HandlerTxnTrace{} type InvokeTxnTrace struct { ValidateInvocation FnInvocation `json:"validate_invocation"` //the trace of the __execute__ call or constructor call, depending on the transaction type (none for declare transactions) - ExecuteInvocation ExecInvocation `json:"execute_invocation"` - FeeTransferInvocation FnInvocation `json:"fee_transfer_invocation"` - StateDiff StateDiff `json:"state_diff"` - Type TransactionType `json:"type"` + ExecuteInvocation ExecInvocation `json:"execute_invocation"` + FeeTransferInvocation FnInvocation `json:"fee_transfer_invocation"` + StateDiff StateDiff `json:"state_diff"` + Type TransactionType `json:"type"` + ExecutionResources ExecutionResources `json:"execution_resources"` } // the execution trace of a declare transaction type DeclareTxnTrace struct { - ValidateInvocation FnInvocation `json:"validate_invocation"` - FeeTransferInvocation FnInvocation `json:"fee_transfer_invocation"` - StateDiff StateDiff `json:"state_diff"` - Type TransactionType `json:"type"` + ValidateInvocation FnInvocation `json:"validate_invocation"` + FeeTransferInvocation FnInvocation `json:"fee_transfer_invocation"` + StateDiff StateDiff `json:"state_diff"` + Type TransactionType `json:"type"` + ExecutionResources ExecutionResources `json:"execution_resources"` } // the execution trace of a deploy account transaction type DeployAccountTxnTrace struct { ValidateInvocation FnInvocation `json:"validate_invocation"` //the trace of the __execute__ call or constructor call, depending on the transaction type (none for declare transactions) - ConstructorInvocation FnInvocation `json:"constructor_invocation"` - FeeTransferInvocation FnInvocation `json:"fee_transfer_invocation"` - StateDiff StateDiff `json:"state_diff"` - Type TransactionType `json:"type"` + ConstructorInvocation FnInvocation `json:"constructor_invocation"` + FeeTransferInvocation FnInvocation `json:"fee_transfer_invocation"` + StateDiff StateDiff `json:"state_diff"` + Type TransactionType `json:"type"` + ExecutionResources ExecutionResources `json:"execution_resources"` } // the execution trace of an L1 handler transaction @@ -113,7 +116,8 @@ type FnInvocation struct { L1Messages []OrderedMsg `json:"messages"` // Resources consumed by the internal call - ExecutionResources ExecutionResources `json:"execution_resources"` + // https://github.com/starkware-libs/starknet-specs/blob/v0.7.0-rc0/api/starknet_trace_api_openrpc.json#L374C1-L374C29 + ComputationResources ComputationResources `json:"execution_resources"` } // A single pair of transaction hash and corresponding trace diff --git a/rpc/types_transaction_receipt.go b/rpc/types_transaction_receipt.go index af2749b3..a848d2cf 100644 --- a/rpc/types_transaction_receipt.go +++ b/rpc/types_transaction_receipt.go @@ -28,8 +28,6 @@ type CommonTransactionReceipt struct { ActualFee FeePayment `json:"actual_fee"` ExecutionStatus TxnExecutionStatus `json:"execution_status"` FinalityStatus TxnFinalityStatus `json:"finality_status"` - BlockHash *felt.Felt `json:"block_hash"` - BlockNumber uint64 `json:"block_number"` Type TransactionType `json:"type,omitempty"` MessagesSent []MsgToL1 `json:"messages_sent"` RevertReason string `json:"revert_reason,omitempty"` @@ -271,109 +269,7 @@ func (tr L1HandlerTransactionReceipt) GetExecutionStatus() TxnExecutionStatus { return tr.ExecutionStatus } -type PendingL1HandlerTransactionReceipt struct { - Type TransactionType `json:"type"` - // The message hash as it appears on the L1 core contract - MsgHash NumAsHex `json:"message_hash"` - PendingCommonTransactionReceiptProperties -} - -func (tr PendingL1HandlerTransactionReceipt) Hash() *felt.Felt { - return tr.TransactionHash -} - -func (tr PendingL1HandlerTransactionReceipt) GetExecutionStatus() TxnExecutionStatus { - return tr.ExecutionStatus -} - -type PendingDeclareTransactionReceipt struct { - Type TransactionType `json:"type"` - PendingCommonTransactionReceiptProperties -} - -func (tr PendingDeclareTransactionReceipt) Hash() *felt.Felt { - return tr.TransactionHash -} - -func (tr PendingDeclareTransactionReceipt) GetExecutionStatus() TxnExecutionStatus { - return tr.ExecutionStatus -} - -type PendingDeployAccountTransactionReceipt struct { - Type TransactionType `json:"type"` - // The address of the deployed contract - ContractAddress *felt.Felt `json:"contract_address"` - PendingCommonTransactionReceiptProperties -} - -// Hash returns the transaction hash of the pending deploy transaction receipt. -// -// Parameters: -// -// none -// -// Returns: -// - *felt.Felt: the transaction hash -func (tr PendingDeployAccountTransactionReceipt) Hash() *felt.Felt { - return tr.TransactionHash -} - -// GetExecutionStatus returns the execution status of the pending deploy transaction receipt. -// -// Parameters: -// -// none -// -// Returns: -// - TxnExecutionStatus: the execution status -func (tr PendingDeployAccountTransactionReceipt) GetExecutionStatus() TxnExecutionStatus { - return tr.ExecutionStatus -} - -type PendingInvokeTransactionReceipt struct { - Type TransactionType `json:"type"` - PendingCommonTransactionReceiptProperties -} - -// Hash returns the transaction hash of the pending deploy transaction receipt. -// -// Parameters: -// -// none -// -// Returns: -// - *felt.Felt: the transaction hash -func (tr PendingInvokeTransactionReceipt) Hash() *felt.Felt { - return tr.TransactionHash -} - -// GetExecutionStatus returns the execution status of the pending deploy transaction receipt. -// -// Parameters: -// -// none -// -// Returns: -// - TxnExecutionStatus: the execution status -func (tr PendingInvokeTransactionReceipt) GetExecutionStatus() TxnExecutionStatus { - return tr.ExecutionStatus -} - -type PendingCommonTransactionReceiptProperties struct { - // TransactionHash The hash identifying the transaction - TransactionHash *felt.Felt `json:"transaction_hash"` - // ActualFee The fee that was charged by the sequencer - ActualFee FeePayment `json:"actual_fee"` - MessagesSent []MsgToL1 `json:"messages_sent"` - ExecutionStatus TxnExecutionStatus `json:"execution_status"` - FinalityStatus TxnFinalityStatus `json:"finality_status"` - RevertReason string `json:"revert_reason"` - // Events The events emitted as part of this transaction - Events []Event `json:"events"` - ExecutionResources ExecutionResources `json:"execution_resources"` -} - -type ExecutionResources struct { +type ComputationResources struct { // The number of Cairo steps used Steps int `json:"steps"` // The number of unused memory cells (each cell is roughly equivalent to a step) @@ -397,7 +293,7 @@ type ExecutionResources struct { } // Validate checks if the fields are non-zero (to match the starknet-specs) -func (er *ExecutionResources) Validate() bool { +func (er *ComputationResources) Validate() bool { if er.Steps == 0 || er.MemoryHoles == 0 || er.RangeCheckApps == 0 || er.PedersenApps == 0 || er.PoseidonApps == 0 || er.ECOPApps == 0 || er.ECDSAApps == 0 || er.BitwiseApps == 0 || er.KeccakApps == 0 || er.SegmentArenaBuiltin == 0 { @@ -406,28 +302,17 @@ func (er *ExecutionResources) Validate() bool { return true } -// Hash returns the transaction hash of the PendingCommonTransactionReceiptProperties. -// -// Parameters: -// -// none -// -// Returns: -// - *felt.Felt: the transaction hash -func (tr PendingCommonTransactionReceiptProperties) Hash() *felt.Felt { - return tr.TransactionHash +// The resources consumed by the transaction, includes both computation and data. +type ExecutionResources struct { + ComputationResources + DataAvailability `json:"data_availability"` } -// GetExecutionStatus returns the execution status of the pending common transaction receipt properties. -// -// Parameters: -// -// none -// -// Returns: -// - TxnExecutionStatus: the execution status -func (tr PendingCommonTransactionReceiptProperties) GetExecutionStatus() TxnExecutionStatus { - return tr.ExecutionStatus +type DataAvailability struct { + // the gas consumed by this transaction's data, 0 if it uses data gas for DA + L1Gas uint `json:"l1_gas"` + // the data gas consumed by this transaction's data, 0 if it uses gas for DA + L1DataGas uint `json:"l1_data_gas"` } type TransactionReceipt interface { @@ -515,28 +400,6 @@ func unmarshalTransactionReceipt(t interface{}) (TransactionReceipt, error) { return nil, fmt.Errorf("unknown transaction type: %v", t) } - // Pending doesn't have a block number - if casted["block_hash"] == nil { - switch TransactionType(typ.(string)) { - case TransactionType_Invoke: - var txn PendingInvokeTransactionReceipt - remarshal(casted, &txn) - return txn, nil - case TransactionType_DeployAccount: - var txn PendingDeployAccountTransactionReceipt - remarshal(casted, &txn) - return txn, nil - case TransactionType_L1Handler: - var txn PendingL1HandlerTransactionReceipt - remarshal(casted, &txn) - return txn, nil - case TransactionType_Declare: - var txn PendingDeclareTransactionReceipt - remarshal(casted, &txn) - return txn, nil - } - } - switch TransactionType(typ.(string)) { case TransactionType_Invoke: var txn InvokeTransactionReceipt @@ -578,3 +441,9 @@ type TxnStatusResp struct { ExecutionStatus TxnExecutionStatus `json:"execution_status,omitempty"` FinalityStatus TxnStatus `json:"finality_status"` } + +type TransactionReceiptWithBlockInfo struct { + TransactionReceipt + BlockHash *felt.Felt `json:"block_hash,omitempty"` + BlockNumber uint `json:"block_number,omitempty"` +}