From 6c244ac664812f1893bccfda4290e3520c6f8b0f Mon Sep 17 00:00:00 2001 From: Rian Hughes Date: Thu, 23 Nov 2023 15:07:09 +0300 Subject: [PATCH] rpcv06 update receipts (#464) * rpcv06 update receipts * small fix * remove pending type field * Fix Receipt Tests * Add testnet tests pass on rpc pkg --- rpc/provider_test.go | 14 +++-- rpc/transaction_test.go | 87 ++++++++++++++++++++++++++------ rpc/types_transaction_receipt.go | 20 ++++++-- rpc/version_test.go | 2 +- 4 files changed, 98 insertions(+), 25 deletions(-) diff --git a/rpc/provider_test.go b/rpc/provider_test.go index d5c99c3b..24dee279 100644 --- a/rpc/provider_test.go +++ b/rpc/provider_test.go @@ -52,7 +52,8 @@ var ( base: "http://localhost:5050/rpc", }, // Used with a mock as a standard configuration, see `mock_test.go`` - "mock": {}, + "mock": {}, + "integration": {}, } ) @@ -67,7 +68,8 @@ var ( // Parameters: // - m: the testing.M struct // Returns: -// none +// +// none func TestMain(m *testing.M) { flag.StringVar(&testEnv, "env", "mock", "set the test environment") flag.Parse() @@ -86,7 +88,7 @@ func beforeEach(t *testing.T) *testConfiguration { godotenv.Load(fmt.Sprintf(".env.%s", testEnv), ".env") testConfig, ok := testConfigurations[testEnv] if !ok { - t.Fatal("env supports mock, testnet, mainnet or devnet") + t.Fatal("env supports mock, testnet, mainnet, devnet, integration") } if testEnv == "mock" { testConfig.provider = &Provider{ @@ -122,7 +124,8 @@ func beforeEach(t *testing.T) *testConfiguration { // Parameters: // - t: the testing object for running the test cases // Returns: -// none +// +// none func TestChainID(t *testing.T) { testConfig := beforeEach(t) @@ -166,7 +169,8 @@ func TestChainID(t *testing.T) { // Parameters: // - t: the testing object for running the test cases // Returns: -// none +// +// none func TestSyncing(t *testing.T) { testConfig := beforeEach(t) diff --git a/rpc/transaction_test.go b/rpc/transaction_test.go index ad961272..4d5814f4 100644 --- a/rpc/transaction_test.go +++ b/rpc/transaction_test.go @@ -109,7 +109,8 @@ func TestTransactionByHash(t *testing.T) { // Parameters: // - t: the testing object for running the test cases // Returns: -// none +// +// none func TestTransactionByBlockIdAndIndex(t *testing.T) { testConfig := beforeEach(t) @@ -169,7 +170,8 @@ func TestTransactionByBlockIdAndIndex(t *testing.T) { // Parameters: // - t: the testing object for running the test cases // Returns: -// none +// +// none func TestTransactionReceipt_MatchesCapturedTransaction(t *testing.T) { testConfig := beforeEach(t) @@ -179,7 +181,7 @@ func TestTransactionReceipt_MatchesCapturedTransaction(t *testing.T) { } var receiptTxn310370_0 = InvokeTransactionReceipt(CommonTransactionReceipt{ TransactionHash: utils.TestHexToFelt(t, "0x40c82f79dd2bc1953fc9b347a3e7ab40fe218ed5740bf4e120f74e8a3c9ac99"), - ActualFee: utils.TestHexToFelt(t, "0x1709a2f3a2"), + ActualFee: FeePayment{Amount: utils.TestHexToFelt(t, "0x1709a2f3a2"), Unit: UnitWei}, Type: "INVOKE", ExecutionStatus: TxnExecutionStatusSUCCEEDED, FinalityStatus: TxnFinalityStatusAcceptedOnL1, @@ -206,6 +208,53 @@ func TestTransactionReceipt_MatchesCapturedTransaction(t *testing.T) { Keys: []*felt.Felt{utils.TestHexToFelt(t, "0xf806f71b19e4744968b37e3fb288e61309ab33a782ea9d11e18f67a1fbb110")}, }, }, + ExecutionResources: ExecutionResources{ + 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, + BlockHash: utils.TestHexToFelt(t, "0x50e864db6b81ce69fbeb70e6a7284ee2febbb9a2e707415de7adab83525e9cd"), + BlockNumber: 319132, + MessagesSent: []MsgToL1{}, + Events: []Event{ + { + FromAddress: utils.TestHexToFelt(t, "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"), + Data: []*felt.Felt{ + utils.TestHexToFelt(t, "0x3f6f3bc663aedc5285d6013cc3ffcbc4341d86ab488b8b68d297f8258793c41"), + utils.TestHexToFelt(t, "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"), + utils.TestHexToFelt(t, "0x16d8b4ad4000"), + 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, "0xa9fa878c35cd3d0191318f89033ca3e5501a3d90e21e3cc9256bdd5cd17fdd")}, + }, + }, + ExecutionResources: ExecutionResources{ + Steps: 615, + MemoryHoles: 4, + RangeCheckApps: 19, + }, }) testSet := map[string][]testSetType{ @@ -217,7 +266,12 @@ func TestTransactionReceipt_MatchesCapturedTransaction(t *testing.T) { }, }, "mainnet": {}, - }[testEnv] + "integration": { + { + TxnHash: utils.TestHexToFelt(t, "0x49728601e0bb2f48ce506b0cbd9c0e2a9e50d95858aa41463f46386dca489fd"), + ExpectedTxnReceipt: receiptTxnIntegration, + }, + }}[testEnv] for _, test := range testSet { spy := NewSpy(testConfig.provider.c) @@ -252,7 +306,8 @@ func TestTransactionReceipt_MatchesCapturedTransaction(t *testing.T) { // Parameters: // - t: the testing object for running the test cases // Returns: -// none +// +// none func TestTransactionReceipt_MatchesStatus(t *testing.T) { testConfig := beforeEach(t) @@ -302,7 +357,8 @@ func TestTransactionReceipt_MatchesStatus(t *testing.T) { // Parameters: // - t: the testing object for running the test cases // Returns: -// none +// +// none func TestDeployOrDeclareReceipt(t *testing.T) { testConfig := beforeEach(t) @@ -313,15 +369,16 @@ func TestDeployOrDeclareReceipt(t *testing.T) { var receiptTxn300114_3 = DeclareTransactionReceipt( CommonTransactionReceipt{ - TransactionHash: utils.TestHexToFelt(t, "0x46a9f52a96b2d226407929e04cb02507e531f7c78b9196fc8c910351d8c33f3"), - ActualFee: utils.TestHexToFelt(t, "0x0"), - FinalityStatus: TxnFinalityStatusAcceptedOnL1, - ExecutionStatus: TxnExecutionStatusSUCCEEDED, - BlockHash: utils.TestHexToFelt(t, "0x184268bfbce24766fa53b65c9c8b30b295e145e8281d543a015b46308e27fdf"), - BlockNumber: 300114, - Type: "DECLARE", - MessagesSent: []MsgToL1{}, - Events: []Event{}, + 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{ diff --git a/rpc/types_transaction_receipt.go b/rpc/types_transaction_receipt.go index cd50c58a..b3bf71e5 100644 --- a/rpc/types_transaction_receipt.go +++ b/rpc/types_transaction_receipt.go @@ -8,12 +8,24 @@ import ( "github.com/NethermindEth/juno/core/felt" ) +type FeePayment struct { + Amount *felt.Felt `json:"amount"` + Unit FeePaymentUnit `json:"unit"` +} + +type FeePaymentUnit string + +const ( + UnitWei FeePaymentUnit = "WEI" + UnitStrk FeePaymentUnit = "STRK" +) + // CommonTransactionReceipt Common properties for a transaction receipt type CommonTransactionReceipt struct { // TransactionHash The hash identifying the transaction TransactionHash *felt.Felt `json:"transaction_hash"` // ActualFee The fee that was charged by the sequencer - ActualFee *felt.Felt `json:"actual_fee"` + ActualFee FeePayment `json:"actual_fee"` ExecutionStatus TxnExecutionStatus `json:"execution_status"` FinalityStatus TxnFinalityStatus `json:"finality_status"` BlockHash *felt.Felt `json:"block_hash"` @@ -22,7 +34,8 @@ type CommonTransactionReceipt struct { MessagesSent []MsgToL1 `json:"messages_sent"` RevertReason string `json:"revert_reason,omitempty"` // Events The events emitted as part of this transaction - Events []Event `json:"events"` + Events []Event `json:"events"` + ExecutionResources ExecutionResources `json:"execution_resources"` } // Hash returns the transaction hash associated with the CommonTransactionReceipt. @@ -350,8 +363,7 @@ 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 *felt.Felt `json:"actual_fee"` - Type TransactionType `json:"type,omitempty"` + ActualFee FeePayment `json:"actual_fee"` MessagesSent []MsgToL1 `json:"messages_sent"` ExecutionStatus TxnExecutionStatus `json:"execution_status"` FinalityStatus TxnFinalityStatus `json:"finality_status"` diff --git a/rpc/version_test.go b/rpc/version_test.go index 57a53fcf..c523d6ac 100644 --- a/rpc/version_test.go +++ b/rpc/version_test.go @@ -20,7 +20,7 @@ func TestSpecVersion(t *testing.T) { "mainnet": {}, "mock": {}, "testnet": {{ - ExpectedResp: "0.5.0", + ExpectedResp: "0.6.0-rc1", }}, }[testEnv]