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] 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) +}