From 8dd8480608a19d0d45be7b478ad6564093073e5b Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Fri, 28 Jun 2024 12:56:39 +0530 Subject: [PATCH 01/10] fix::> Added a method to BroadcastInvokeTxnType --- rpc/types_broadcast_transaction.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/rpc/types_broadcast_transaction.go b/rpc/types_broadcast_transaction.go index f5149d44..4135bd36 100644 --- a/rpc/types_broadcast_transaction.go +++ b/rpc/types_broadcast_transaction.go @@ -13,7 +13,9 @@ var ( _ BroadcastTxn = BroadcastDeployAccountTxn{} ) -type BroadcastInvokeTxnType interface{} +type BroadcastInvokeTxnType interface { + InvokeType() string +} var ( _ BroadcastInvokeTxnType = BroadcastInvokev0Txn{} @@ -40,14 +42,26 @@ type BroadcastInvokev0Txn struct { InvokeTxnV0 } +func (tx BroadcastInvokev0Txn) InvokeType() string { + return "BroadcastInvokev0Txn" +} + type BroadcastInvokev1Txn struct { InvokeTxnV1 } +func (tx BroadcastInvokev1Txn) InvokeType() string { + return "BroadcastInvokev1Txn" +} + type BroadcastInvokev3Txn struct { InvokeTxnV3 } +func (tx BroadcastInvokev3Txn) InvokeType() string { + return "BroadcastInvokev3Txn" +} + type BroadcastDeclareTxnV1 struct { Type TransactionType `json:"type"` // SenderAddress the address of the account contract sending the declaration transaction From 039a56390f64c9715f31010ca53bdce295d0149d Mon Sep 17 00:00:00 2001 From: Mattia D'Antonio Date: Fri, 28 Jun 2024 18:50:37 +0200 Subject: [PATCH 02/10] Migrate from test-go to stretchr --- account/account_test.go | 2 +- contracts/contracts_test.go | 4 ++-- go.mod | 3 +-- go.sum | 6 ++---- hash/hash_test.go | 2 +- rpc/block_test.go | 4 ++-- rpc/call_test.go | 2 +- rpc/contract_test.go | 2 +- rpc/errors_test.go | 2 +- rpc/events_test.go | 2 +- rpc/provider_test.go | 2 +- rpc/trace_test.go | 2 +- rpc/transaction_test.go | 2 +- rpc/types_block_test.go | 2 +- rpc/version_test.go | 2 +- rpc/write_test.go | 2 +- utils/Test.go | 2 +- 17 files changed, 20 insertions(+), 23 deletions(-) diff --git a/account/account_test.go b/account/account_test.go index e857532d..6e5af819 100644 --- a/account/account_test.go +++ b/account/account_test.go @@ -20,7 +20,7 @@ import ( "github.com/NethermindEth/starknet.go/utils" "github.com/golang/mock/gomock" "github.com/joho/godotenv" - "github.com/test-go/testify/require" + "github.com/stretchr/testify/require" ) var ( diff --git a/contracts/contracts_test.go b/contracts/contracts_test.go index 0f294407..8b36e114 100644 --- a/contracts/contracts_test.go +++ b/contracts/contracts_test.go @@ -9,8 +9,8 @@ import ( "github.com/NethermindEth/starknet.go/contracts" "github.com/NethermindEth/starknet.go/rpc" "github.com/NethermindEth/starknet.go/utils" - "github.com/test-go/testify/assert" - "github.com/test-go/testify/require" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) // TestUnmarshalContractClass is a test function to unmarshal a contract class. diff --git a/go.mod b/go.mod index 3c4f0d5c..c83419ca 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/joho/godotenv v1.4.0 github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249 github.com/pkg/errors v0.9.1 - github.com/test-go/testify v1.1.4 + github.com/stretchr/testify v1.9.0 go.uber.org/mock v0.4.0 golang.org/x/crypto v0.17.0 golang.org/x/net v0.18.0 @@ -30,7 +30,6 @@ require ( github.com/mmcloughlin/addchain v0.4.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect - github.com/stretchr/testify v1.8.4 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect github.com/x448/float16 v0.8.4 // indirect diff --git a/go.sum b/go.sum index 0f059d74..6d2f3cfd 100644 --- a/go.sum +++ b/go.sum @@ -96,12 +96,10 @@ github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1 github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4= github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= -github.com/test-go/testify v1.1.4 h1:Tf9lntrKUMHiXQ07qBScBTSA0dhYQlu83hswqelv1iE= -github.com/test-go/testify v1.1.4/go.mod h1:rH7cfJo/47vWGdi4GPj16x3/t1xGOj2YxzmNQzk2ghU= github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= diff --git a/hash/hash_test.go b/hash/hash_test.go index f6dc989a..415cd081 100644 --- a/hash/hash_test.go +++ b/hash/hash_test.go @@ -8,7 +8,7 @@ import ( "github.com/NethermindEth/starknet.go/contracts" "github.com/NethermindEth/starknet.go/hash" "github.com/NethermindEth/starknet.go/rpc" - "github.com/test-go/testify/require" + "github.com/stretchr/testify/require" ) // TestUnmarshalCasmClassHash is a test function that tests the unmarshaling of a CasmClass hash. diff --git a/rpc/block_test.go b/rpc/block_test.go index 508d23c7..3d57a638 100644 --- a/rpc/block_test.go +++ b/rpc/block_test.go @@ -9,8 +9,8 @@ import ( "github.com/NethermindEth/juno/core/felt" "github.com/NethermindEth/starknet.go/utils" "github.com/google/go-cmp/cmp" - "github.com/test-go/testify/assert" - "github.com/test-go/testify/require" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) // TestBlockNumber is a test function to check the behavior of the BlockNumber function and check the returned value is strictly positive. diff --git a/rpc/call_test.go b/rpc/call_test.go index 39e4788f..73d44453 100644 --- a/rpc/call_test.go +++ b/rpc/call_test.go @@ -6,7 +6,7 @@ import ( "github.com/NethermindEth/juno/core/felt" "github.com/NethermindEth/starknet.go/utils" - "github.com/test-go/testify/require" + "github.com/stretchr/testify/require" ) // TestCall tests the Call function. diff --git a/rpc/contract_test.go b/rpc/contract_test.go index 68a6a843..ee9d193d 100644 --- a/rpc/contract_test.go +++ b/rpc/contract_test.go @@ -8,7 +8,7 @@ import ( "github.com/NethermindEth/juno/core/felt" "github.com/NethermindEth/starknet.go/utils" - "github.com/test-go/testify/require" + "github.com/stretchr/testify/require" ) // TestClassAt tests the ClassAt function. diff --git a/rpc/errors_test.go b/rpc/errors_test.go index f91f9803..e0981d3b 100644 --- a/rpc/errors_test.go +++ b/rpc/errors_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - "github.com/test-go/testify/require" + "github.com/stretchr/testify/require" ) func TestRPCError(t *testing.T) { diff --git a/rpc/events_test.go b/rpc/events_test.go index 6565ece7..9dd20fea 100644 --- a/rpc/events_test.go +++ b/rpc/events_test.go @@ -6,7 +6,7 @@ import ( "github.com/NethermindEth/juno/core/felt" "github.com/NethermindEth/starknet.go/utils" - "github.com/test-go/testify/require" + "github.com/stretchr/testify/require" ) // TestEvents is a test function for testing the Events function. diff --git a/rpc/provider_test.go b/rpc/provider_test.go index f09431f1..b1e8da67 100644 --- a/rpc/provider_test.go +++ b/rpc/provider_test.go @@ -15,7 +15,7 @@ import ( "github.com/NethermindEth/juno/core/felt" "github.com/joho/godotenv" - "github.com/test-go/testify/require" + "github.com/stretchr/testify/require" ) const ( diff --git a/rpc/trace_test.go b/rpc/trace_test.go index cb1da7d5..66a6db14 100644 --- a/rpc/trace_test.go +++ b/rpc/trace_test.go @@ -8,7 +8,7 @@ import ( "github.com/NethermindEth/juno/core/felt" "github.com/NethermindEth/starknet.go/utils" - "github.com/test-go/testify/require" + "github.com/stretchr/testify/require" ) // TestTransactionTrace is a function that tests the TransactionTrace function. diff --git a/rpc/transaction_test.go b/rpc/transaction_test.go index 12eee403..1ac9df2b 100644 --- a/rpc/transaction_test.go +++ b/rpc/transaction_test.go @@ -6,7 +6,7 @@ import ( "github.com/NethermindEth/juno/core/felt" "github.com/NethermindEth/starknet.go/utils" - "github.com/test-go/testify/require" + "github.com/stretchr/testify/require" ) // TestTransactionByHash tests transaction by hash diff --git a/rpc/types_block_test.go b/rpc/types_block_test.go index d2091f77..a1537f1b 100644 --- a/rpc/types_block_test.go +++ b/rpc/types_block_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/NethermindEth/juno/core/felt" - "github.com/test-go/testify/require" + "github.com/stretchr/testify/require" ) // TestBlockID_Marshal tests the MarshalJSON method of the BlockID struct. diff --git a/rpc/version_test.go b/rpc/version_test.go index d4d889ab..a22eb134 100644 --- a/rpc/version_test.go +++ b/rpc/version_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - "github.com/test-go/testify/require" + "github.com/stretchr/testify/require" ) // TestSpecVersion tests starknet_specVersion diff --git a/rpc/write_test.go b/rpc/write_test.go index 90c2d1c7..8567583b 100644 --- a/rpc/write_test.go +++ b/rpc/write_test.go @@ -9,7 +9,7 @@ import ( "github.com/NethermindEth/juno/core/felt" "github.com/NethermindEth/starknet.go/utils" - "github.com/test-go/testify/require" + "github.com/stretchr/testify/require" ) func TestDeclareTransaction(t *testing.T) { diff --git a/utils/Test.go b/utils/Test.go index c300da55..c3da1fe4 100644 --- a/utils/Test.go +++ b/utils/Test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/NethermindEth/juno/core/felt" - "github.com/test-go/testify/require" + "github.com/stretchr/testify/require" ) // TestHexToFelt generates a felt.Felt from a hexadecimal string. From c58cea9395d32ed60c9bc812ad096481c23125a2 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Sat, 29 Jun 2024 17:13:26 +0530 Subject: [PATCH 03/10] fix::> Error treated + implemented InvokeType for remaining structs --- rpc/types_transaction.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/rpc/types_transaction.go b/rpc/types_transaction.go index 8420fe60..a1014312 100644 --- a/rpc/types_transaction.go +++ b/rpc/types_transaction.go @@ -43,6 +43,10 @@ type InvokeTxnV0 struct { FunctionCall } +func (tx InvokeTxnV0) InvokeType() string { + return "InvokeTxn: V0" +} + type InvokeTxnV1 struct { MaxFee *felt.Felt `json:"max_fee"` Version TransactionVersion `json:"version"` @@ -53,6 +57,11 @@ type InvokeTxnV1 struct { // The data expected by the account's `execute` function (in most usecases, this includes the called contract address and a function selector) Calldata []*felt.Felt `json:"calldata"` } + +func (tx InvokeTxnV1) InvokeType() string { + return "InvokeTxn: V1" +} + type InvokeTxnV3 struct { Type TransactionType `json:"type"` SenderAddress *felt.Felt `json:"sender_address"` @@ -72,6 +81,10 @@ type InvokeTxnV3 struct { FeeMode DataAvailabilityMode `json:"fee_data_availability_mode"` } +func (tx InvokeTxnV3) InvokeType() string { + return "InvokeTxn: V2" +} + type L1HandlerTxn struct { Type TransactionType `json:"type,omitempty"` // Version of the transaction scheme From 730761e00e853aaa355376afcacdd7f75ebc5dc6 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Mon, 1 Jul 2024 14:53:14 +0530 Subject: [PATCH 04/10] fix::> Removed the useless function and Typecasted InvokeTx with BroadcastInvokevTx --- rpc/types_transaction.go | 12 ------------ rpc/write_test.go | 8 ++++---- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/rpc/types_transaction.go b/rpc/types_transaction.go index a1014312..b36627e9 100644 --- a/rpc/types_transaction.go +++ b/rpc/types_transaction.go @@ -43,10 +43,6 @@ type InvokeTxnV0 struct { FunctionCall } -func (tx InvokeTxnV0) InvokeType() string { - return "InvokeTxn: V0" -} - type InvokeTxnV1 struct { MaxFee *felt.Felt `json:"max_fee"` Version TransactionVersion `json:"version"` @@ -58,10 +54,6 @@ type InvokeTxnV1 struct { Calldata []*felt.Felt `json:"calldata"` } -func (tx InvokeTxnV1) InvokeType() string { - return "InvokeTxn: V1" -} - type InvokeTxnV3 struct { Type TransactionType `json:"type"` SenderAddress *felt.Felt `json:"sender_address"` @@ -81,10 +73,6 @@ type InvokeTxnV3 struct { FeeMode DataAvailabilityMode `json:"fee_data_availability_mode"` } -func (tx InvokeTxnV3) InvokeType() string { - return "InvokeTxn: V2" -} - type L1HandlerTxn struct { Type TransactionType `json:"type,omitempty"` // Version of the transaction scheme diff --git a/rpc/write_test.go b/rpc/write_test.go index 8567583b..d6af1535 100644 --- a/rpc/write_test.go +++ b/rpc/write_test.go @@ -105,7 +105,7 @@ func TestAddInvokeTransaction(t *testing.T) { "mainnet": {}, "mock": { { - InvokeTx: InvokeTxnV1{SenderAddress: new(felt.Felt).SetUint64(123)}, + InvokeTx: BroadcastInvokev1Txn{InvokeTxnV1{SenderAddress: new(felt.Felt).SetUint64(123)}}, ExpectedResp: AddInvokeTransactionResponse{&felt.Zero}, ExpectedError: &RPCError{ Code: ErrUnexpectedError.Code, @@ -113,12 +113,12 @@ func TestAddInvokeTransaction(t *testing.T) { Data: "Something crazy happened"}, }, { - InvokeTx: InvokeTxnV1{}, + InvokeTx: BroadcastInvokev1Txn{InvokeTxnV1{}}, ExpectedResp: AddInvokeTransactionResponse{utils.TestHexToFelt(t, "0xdeadbeef")}, ExpectedError: nil, }, { - InvokeTx: InvokeTxnV3{ + InvokeTx: BroadcastInvokev3Txn{InvokeTxnV3{ Type: TransactionType_Invoke, Version: TransactionV3, Signature: []*felt.Felt{ @@ -159,7 +159,7 @@ func TestAddInvokeTransaction(t *testing.T) { utils.TestHexToFelt(t, "0x287acddb27a2f9ba7f2612d72788dc96a5b30e401fc1e8072250940e024a587"), }, AccountDeploymentData: []*felt.Felt{}, - }, + }}, ExpectedResp: AddInvokeTransactionResponse{utils.TestHexToFelt(t, "0x49728601e0bb2f48ce506b0cbd9c0e2a9e50d95858aa41463f46386dca489fd")}, ExpectedError: nil, }, From f3c93252dd846828ffc58b1bb27438333908c583 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Mon, 1 Jul 2024 14:55:52 +0530 Subject: [PATCH 05/10] fix::> Typecasted InvokeTx with Respective BroadcastInvokeTx --- examples/deployContractUDC/main.go | 19 ++++++++++--------- examples/simpleInvoke/main.go | 19 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/examples/deployContractUDC/main.go b/examples/deployContractUDC/main.go index 54d0d58c..31ddc0c5 100644 --- a/examples/deployContractUDC/main.go +++ b/examples/deployContractUDC/main.go @@ -73,13 +73,14 @@ func main() { } // Build the InvokeTx struct - InvokeTx := rpc.InvokeTxnV1{ - MaxFee: new(felt.Felt).SetUint64(100000000000000), - Version: rpc.TransactionV1, - Nonce: nonce, - Type: rpc.TransactionType_Invoke, - SenderAddress: accnt.AccountAddress, - } + InvokeTx := rpc.BroadcastInvokev1Txn{ + InvokeTxnV1: rpc.InvokeTxnV1{ + MaxFee: new(felt.Felt).SetUint64(100000000000000), + Version: rpc.TransactionV1, + Nonce: nonce, + Type: rpc.TransactionType_Invoke, + SenderAddress: accnt.AccountAddress, + }} // Convert the contractAddress from hex to felt contractAddress, err := utils.HexToFelt(UDCAddress) @@ -101,7 +102,7 @@ func main() { } // Sign the transaction - err = accnt.SignInvokeTransaction(context.Background(), &InvokeTx) + err = accnt.SignInvokeTransaction(context.Background(), &InvokeTx.InvokeTxnV1) if err != nil { panic(err) } @@ -120,7 +121,7 @@ func main() { } InvokeTx.MaxFee = new(felt.Felt).SetUint64(newFee + newFee/5) // fee + 20% to be sure // Signing the transaction again - err = accnt.SignInvokeTransaction(context.Background(), &InvokeTx) + err = accnt.SignInvokeTransaction(context.Background(), &InvokeTx.InvokeTxnV1) if err != nil { panic(err) } diff --git a/examples/simpleInvoke/main.go b/examples/simpleInvoke/main.go index 37749e74..2ed8ca89 100644 --- a/examples/simpleInvoke/main.go +++ b/examples/simpleInvoke/main.go @@ -64,13 +64,14 @@ func main() { } // Building the InvokeTx struct - InvokeTx := rpc.InvokeTxnV1{ - MaxFee: new(felt.Felt).SetUint64(100000000000000), - Version: rpc.TransactionV1, - Nonce: nonce, - Type: rpc.TransactionType_Invoke, - SenderAddress: accnt.AccountAddress, - } + InvokeTx := rpc.BroadcastInvokev1Txn{ + InvokeTxnV1: rpc.InvokeTxnV1{ + MaxFee: new(felt.Felt).SetUint64(100000000000000), + Version: rpc.TransactionV1, + Nonce: nonce, + Type: rpc.TransactionType_Invoke, + SenderAddress: accnt.AccountAddress, + }} // Converting the contractAddress from hex to felt contractAddress, err := utils.HexToFelt(someContract) @@ -93,7 +94,7 @@ func main() { } // Signing of the transaction that is done by the account - err = accnt.SignInvokeTransaction(context.Background(), &InvokeTx) + err = accnt.SignInvokeTransaction(context.Background(), &InvokeTx.InvokeTxnV1) if err != nil { panic(err) } @@ -112,7 +113,7 @@ func main() { } InvokeTx.MaxFee = new(felt.Felt).SetUint64(newFee + newFee/5) // fee + 20% to be sure // Signing the transaction again - err = accnt.SignInvokeTransaction(context.Background(), &InvokeTx) + err = accnt.SignInvokeTransaction(context.Background(), &InvokeTx.InvokeTxnV1) if err != nil { panic(err) } From 701254d125dab5a416fcda43ff1746ce847cedd8 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Mon, 1 Jul 2024 14:56:59 +0530 Subject: [PATCH 06/10] fix::> Removed possible error in Test for smooth Running --- account/account_test.go | 51 ++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/account/account_test.go b/account/account_test.go index 6e5af819..732d358e 100644 --- a/account/account_test.go +++ b/account/account_test.go @@ -166,14 +166,15 @@ func TestTransactionHashInvoke(t *testing.T) { mockRpcProvider.EXPECT().ChainID(context.Background()).Return(test.ChainID, nil) account, err := account.NewAccount(mockRpcProvider, test.AccountAddress, test.PubKey, ks, 0) require.NoError(t, err, "error returned from account.NewAccount()") - invokeTxn := rpc.InvokeTxnV1{ - Calldata: test.FnCall.Calldata, - Nonce: test.TxDetails.Nonce, - MaxFee: test.TxDetails.MaxFee, - SenderAddress: account.AccountAddress, - Version: test.TxDetails.Version, - } - hash, err := account.TransactionHashInvoke(invokeTxn) + invokeTxn := rpc.BroadcastInvokev1Txn{ + InvokeTxnV1: rpc.InvokeTxnV1{ + Calldata: test.FnCall.Calldata, + Nonce: test.TxDetails.Nonce, + MaxFee: test.TxDetails.MaxFee, + SenderAddress: account.AccountAddress, + Version: test.TxDetails.Version, + }} + hash, err := account.TransactionHashInvoke(invokeTxn.InvokeTxnV1) require.NoError(t, err, "error returned from account.TransactionHash()") require.Equal(t, test.ExpectedHash.String(), hash.String(), "transaction hash does not match expected") }) @@ -444,7 +445,7 @@ func TestAddInvoke(t *testing.T) { AccountAddress *felt.Felt PubKey *felt.Felt PrivKey *felt.Felt - InvokeTx rpc.InvokeTxnV1 + InvokeTx rpc.BroadcastInvokev1Txn FnCall rpc.FunctionCall TxDetails rpc.TxDetails } @@ -460,13 +461,14 @@ func TestAddInvoke(t *testing.T) { SetKS: true, PubKey: utils.TestHexToFelt(t, "0x022288424ec8116c73d2e2ed3b0663c5030d328d9c0fb44c2b54055db467f31e"), PrivKey: utils.TestHexToFelt(t, "0x04818374f8071c3b4c3070ff7ce766e7b9352628df7b815ea4de26e0fadb5cc9"), // - InvokeTx: rpc.InvokeTxnV1{ - Nonce: new(felt.Felt).SetUint64(5), - MaxFee: utils.TestHexToFelt(t, "0x26112A960026"), - Version: rpc.TransactionV1, - Type: rpc.TransactionType_Invoke, - SenderAddress: utils.TestHexToFelt(t, "0x01AE6Fe02FcD9f61A3A8c30D68a8a7c470B0d7dD6F0ee685d5BBFa0d79406ff9"), - }, + InvokeTx: rpc.BroadcastInvokev1Txn{ + InvokeTxnV1: rpc.InvokeTxnV1{ + Nonce: new(felt.Felt).SetUint64(5), + MaxFee: utils.TestHexToFelt(t, "0x26112A960026"), + Version: rpc.TransactionV1, + Type: rpc.TransactionType_Invoke, + SenderAddress: utils.TestHexToFelt(t, "0x01AE6Fe02FcD9f61A3A8c30D68a8a7c470B0d7dD6F0ee685d5BBFa0d79406ff9"), + }}, FnCall: rpc.FunctionCall{ ContractAddress: utils.TestHexToFelt(t, "0x04daadb9d30c887e1ab2cf7d78dfe444a77aab5a49c3353d6d9977e7ed669902"), EntryPointSelector: utils.TestHexToFelt(t, "0x166d775d0cf161f1ce9b90698485f0c7a0e249af1c4b38126bddb37859737ac"), @@ -483,13 +485,14 @@ func TestAddInvoke(t *testing.T) { SetKS: true, PubKey: utils.TestHexToFelt(t, "0x022288424ec8116c73d2e2ed3b0663c5030d328d9c0fb44c2b54055db467f31e"), PrivKey: utils.TestHexToFelt(t, "0x04818374f8071c3b4c3070ff7ce766e7b9352628df7b815ea4de26e0fadb5cc9"), - InvokeTx: rpc.InvokeTxnV1{ - Nonce: new(felt.Felt).SetUint64(8), - MaxFee: utils.TestHexToFelt(t, "0x1f6410500832"), - Version: rpc.TransactionV1, - Type: rpc.TransactionType_Invoke, - SenderAddress: utils.TestHexToFelt(t, "0x01AE6Fe02FcD9f61A3A8c30D68a8a7c470B0d7dD6F0ee685d5BBFa0d79406ff9"), - }, + InvokeTx: rpc.BroadcastInvokev1Txn{ + InvokeTxnV1: rpc.InvokeTxnV1{ + Nonce: new(felt.Felt).SetUint64(8), + MaxFee: utils.TestHexToFelt(t, "0x1f6410500832"), + Version: rpc.TransactionV1, + Type: rpc.TransactionType_Invoke, + SenderAddress: utils.TestHexToFelt(t, "0x01AE6Fe02FcD9f61A3A8c30D68a8a7c470B0d7dD6F0ee685d5BBFa0d79406ff9"), + }}, FnCall: rpc.FunctionCall{ ContractAddress: utils.TestHexToFelt(t, "0x04daadb9d30c887e1ab2cf7d78dfe444a77aab5a49c3353d6d9977e7ed669902"), EntryPointSelector: utils.TestHexToFelt(t, "0x166d775d0cf161f1ce9b90698485f0c7a0e249af1c4b38126bddb37859737ac"), @@ -520,7 +523,7 @@ func TestAddInvoke(t *testing.T) { test.InvokeTx.Calldata, err = acnt.FmtCalldata([]rpc.FunctionCall{test.FnCall}) require.NoError(t, err) - err = acnt.SignInvokeTransaction(context.Background(), &test.InvokeTx) + err = acnt.SignInvokeTransaction(context.Background(), &test.InvokeTx.InvokeTxnV1) require.NoError(t, err) resp, err := acnt.AddInvokeTransaction(context.Background(), test.InvokeTx) From 462b97878be248eb9da366d8bab4d4a5052c4837 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Wed, 3 Jul 2024 11:06:16 +0530 Subject: [PATCH 07/10] fix::> Changed the impl of interface to return the Calldata of the txn --- rpc/types_broadcast_transaction.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/rpc/types_broadcast_transaction.go b/rpc/types_broadcast_transaction.go index 4135bd36..7d4bf55f 100644 --- a/rpc/types_broadcast_transaction.go +++ b/rpc/types_broadcast_transaction.go @@ -14,7 +14,7 @@ var ( ) type BroadcastInvokeTxnType interface { - InvokeType() string + GetCalldata() []*felt.Felt } var ( @@ -42,24 +42,24 @@ type BroadcastInvokev0Txn struct { InvokeTxnV0 } -func (tx BroadcastInvokev0Txn) InvokeType() string { - return "BroadcastInvokev0Txn" +func (tx BroadcastInvokev0Txn) GetCalldata() []*felt.Felt { + return tx.InvokeTxnV0.FunctionCall.Calldata } type BroadcastInvokev1Txn struct { InvokeTxnV1 } -func (tx BroadcastInvokev1Txn) InvokeType() string { - return "BroadcastInvokev1Txn" +func (tx BroadcastInvokev1Txn) GetCalldata() []*felt.Felt { + return tx.Calldata } type BroadcastInvokev3Txn struct { InvokeTxnV3 } -func (tx BroadcastInvokev3Txn) InvokeType() string { - return "BroadcastInvokev3Txn" +func (tx BroadcastInvokev3Txn) GetCalldata() []*felt.Felt { + return tx.Calldata } type BroadcastDeclareTxnV1 struct { From d896b27d802f5bdaca00f355b721f3465e5887e1 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Wed, 3 Jul 2024 11:13:18 +0530 Subject: [PATCH 08/10] fix::> write_test are all working fine --- rpc/mock_test.go | 8 ++--- rpc/write_test.go | 81 ++++++++++++++++++++++++----------------------- 2 files changed, 45 insertions(+), 44 deletions(-) diff --git a/rpc/mock_test.go b/rpc/mock_test.go index e1d93df5..5a827cba 100644 --- a/rpc/mock_test.go +++ b/rpc/mock_test.go @@ -342,7 +342,7 @@ func mock_starknet_getTransactionReceipt(result interface{}, method string, args } arg0Felt := args[0].(*felt.Felt) - l1BlockHash,err:=new(felt.Felt).SetString("0x74011377f326265f5a54e27a27968355e7033ad1de11b77b225374875aff519") + l1BlockHash, err := new(felt.Felt).SetString("0x74011377f326265f5a54e27a27968355e7033ad1de11b77b225374875aff519") if err != nil { return err } @@ -369,7 +369,7 @@ func mock_starknet_getTransactionReceipt(result interface{}, method string, args } return json.Unmarshal(txnReceipt, &r) - } else if arg0Felt.Equal(l1BlockHash){ + } else if arg0Felt.Equal(l1BlockHash) { var txnRec TransactionReceiptWithBlockInfo read, err := os.ReadFile("tests/receipt/0x74011377f326265f5a54e27a27968355e7033ad1de11b77b225374875aff519.json") if err != nil { @@ -779,7 +779,7 @@ func mock_starknet_addInvokeTransaction(result interface{}, method string, args return errors.Wrap(errWrongArgs, fmt.Sprint("wrong number of args ", len(args))) } switch invokeTx := args[0].(type) { - case InvokeTxnV1: + case BroadcastInvokev1Txn: if invokeTx.SenderAddress != nil { if invokeTx.SenderAddress.Equal(new(felt.Felt).SetUint64(123)) { unexpErr := *ErrUnexpectedError @@ -802,7 +802,7 @@ func mock_starknet_addInvokeTransaction(result interface{}, method string, args return err } return nil - case InvokeTxnV3: + case BroadcastInvokev3Txn: deadbeefFelt, err := utils.HexToFelt("0x49728601e0bb2f48ce506b0cbd9c0e2a9e50d95858aa41463f46386dca489fd") if err != nil { return err diff --git a/rpc/write_test.go b/rpc/write_test.go index d6af1535..0b3fd110 100644 --- a/rpc/write_test.go +++ b/rpc/write_test.go @@ -118,48 +118,49 @@ func TestAddInvokeTransaction(t *testing.T) { ExpectedError: nil, }, { - InvokeTx: BroadcastInvokev3Txn{InvokeTxnV3{ - Type: TransactionType_Invoke, - Version: TransactionV3, - Signature: []*felt.Felt{ - utils.TestHexToFelt(t, "0x71a9b2cd8a8a6a4ca284dcddcdefc6c4fd20b92c1b201bd9836e4ce376fad16"), - utils.TestHexToFelt(t, "0x6bef4745194c9447fdc8dd3aec4fc738ab0a560b0d2c7bf62fbf58aef3abfc5"), - }, - Nonce: utils.TestHexToFelt(t, "0xe97"), - NonceDataMode: DAModeL1, - FeeMode: DAModeL1, - ResourceBounds: ResourceBoundsMapping{ - L1Gas: ResourceBounds{ - MaxAmount: "0x186a0", - MaxPricePerUnit: "0x5af3107a4000", + InvokeTx: BroadcastInvokev3Txn{ + InvokeTxnV3{ + Type: TransactionType_Invoke, + Version: TransactionV3, + Signature: []*felt.Felt{ + utils.TestHexToFelt(t, "0x71a9b2cd8a8a6a4ca284dcddcdefc6c4fd20b92c1b201bd9836e4ce376fad16"), + utils.TestHexToFelt(t, "0x6bef4745194c9447fdc8dd3aec4fc738ab0a560b0d2c7bf62fbf58aef3abfc5"), }, - L2Gas: ResourceBounds{ - MaxAmount: "0x0", - MaxPricePerUnit: "0x0", + Nonce: utils.TestHexToFelt(t, "0xe97"), + NonceDataMode: DAModeL1, + FeeMode: DAModeL1, + ResourceBounds: ResourceBoundsMapping{ + L1Gas: ResourceBounds{ + MaxAmount: "0x186a0", + MaxPricePerUnit: "0x5af3107a4000", + }, + L2Gas: ResourceBounds{ + MaxAmount: "0x0", + MaxPricePerUnit: "0x0", + }, }, - }, - Tip: "", - PayMasterData: []*felt.Felt{}, - SenderAddress: utils.TestHexToFelt(t, "0x3f6f3bc663aedc5285d6013cc3ffcbc4341d86ab488b8b68d297f8258793c41"), - Calldata: []*felt.Felt{ - utils.TestHexToFelt(t, "0x2"), - utils.TestHexToFelt(t, "0x450703c32370cf7ffff540b9352e7ee4ad583af143a361155f2b485c0c39684"), - utils.TestHexToFelt(t, "0x27c3334165536f239cfd400ed956eabff55fc60de4fb56728b6a4f6b87db01c"), - utils.TestHexToFelt(t, "0x0"), - utils.TestHexToFelt(t, "0x4"), - utils.TestHexToFelt(t, "0x4c312760dfd17a954cdd09e76aa9f149f806d88ec3e402ffaf5c4926f568a42"), - utils.TestHexToFelt(t, "0x5df99ae77df976b4f0e5cf28c7dcfe09bd6e81aab787b19ac0c08e03d928cf"), - utils.TestHexToFelt(t, "0x4"), - utils.TestHexToFelt(t, "0x1"), - utils.TestHexToFelt(t, "0x5"), - utils.TestHexToFelt(t, "0x450703c32370cf7ffff540b9352e7ee4ad583af143a361155f2b485c0c39684"), - utils.TestHexToFelt(t, "0x5df99ae77df976b4f0e5cf28c7dcfe09bd6e81aab787b19ac0c08e03d928cf"), - utils.TestHexToFelt(t, "0x1"), - utils.TestHexToFelt(t, "0x7fe4fd616c7fece1244b3616bb516562e230be8c9f29668b46ce0369d5ca829"), - utils.TestHexToFelt(t, "0x287acddb27a2f9ba7f2612d72788dc96a5b30e401fc1e8072250940e024a587"), - }, - AccountDeploymentData: []*felt.Felt{}, - }}, + Tip: "", + PayMasterData: []*felt.Felt{}, + SenderAddress: utils.TestHexToFelt(t, "0x3f6f3bc663aedc5285d6013cc3ffcbc4341d86ab488b8b68d297f8258793c41"), + Calldata: []*felt.Felt{ + utils.TestHexToFelt(t, "0x2"), + utils.TestHexToFelt(t, "0x450703c32370cf7ffff540b9352e7ee4ad583af143a361155f2b485c0c39684"), + utils.TestHexToFelt(t, "0x27c3334165536f239cfd400ed956eabff55fc60de4fb56728b6a4f6b87db01c"), + utils.TestHexToFelt(t, "0x0"), + utils.TestHexToFelt(t, "0x4"), + utils.TestHexToFelt(t, "0x4c312760dfd17a954cdd09e76aa9f149f806d88ec3e402ffaf5c4926f568a42"), + utils.TestHexToFelt(t, "0x5df99ae77df976b4f0e5cf28c7dcfe09bd6e81aab787b19ac0c08e03d928cf"), + utils.TestHexToFelt(t, "0x4"), + utils.TestHexToFelt(t, "0x1"), + utils.TestHexToFelt(t, "0x5"), + utils.TestHexToFelt(t, "0x450703c32370cf7ffff540b9352e7ee4ad583af143a361155f2b485c0c39684"), + utils.TestHexToFelt(t, "0x5df99ae77df976b4f0e5cf28c7dcfe09bd6e81aab787b19ac0c08e03d928cf"), + utils.TestHexToFelt(t, "0x1"), + utils.TestHexToFelt(t, "0x7fe4fd616c7fece1244b3616bb516562e230be8c9f29668b46ce0369d5ca829"), + utils.TestHexToFelt(t, "0x287acddb27a2f9ba7f2612d72788dc96a5b30e401fc1e8072250940e024a587"), + }, + AccountDeploymentData: []*felt.Felt{}, + }}, ExpectedResp: AddInvokeTransactionResponse{utils.TestHexToFelt(t, "0x49728601e0bb2f48ce506b0cbd9c0e2a9e50d95858aa41463f46386dca489fd")}, ExpectedError: nil, }, From a37487b5baf3001720a1842134ce44b1125659be Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Wed, 3 Jul 2024 20:17:28 +0530 Subject: [PATCH 09/10] fix::> implemented Go Struct Embedding --- rpc/types_broadcast_transaction.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/types_broadcast_transaction.go b/rpc/types_broadcast_transaction.go index 7d4bf55f..46fbcc8d 100644 --- a/rpc/types_broadcast_transaction.go +++ b/rpc/types_broadcast_transaction.go @@ -43,7 +43,7 @@ type BroadcastInvokev0Txn struct { } func (tx BroadcastInvokev0Txn) GetCalldata() []*felt.Felt { - return tx.InvokeTxnV0.FunctionCall.Calldata + return tx.Calldata } type BroadcastInvokev1Txn struct { From 9d42a78e319e15595f78e9ab308b4036e0794482 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash <95116715+PsychoPunkSage@users.noreply.github.com> Date: Thu, 4 Jul 2024 17:23:07 +0530 Subject: [PATCH 10/10] chore::> Constrain BroadcastDeclare and BroadcastDeployAccount (#585) * constrain the BroadcastDeployAccount and broadcastDeclare interfaces --- rpc/mock_test.go | 4 +- rpc/types_broadcast_transaction.go | 49 ++++++++----- rpc/write.go | 8 --- rpc/write_test.go | 110 +++++++++++++++-------------- 4 files changed, 88 insertions(+), 83 deletions(-) diff --git a/rpc/mock_test.go b/rpc/mock_test.go index 5a827cba..b9b2d903 100644 --- a/rpc/mock_test.go +++ b/rpc/mock_test.go @@ -643,7 +643,7 @@ func mock_starknet_addDeclareTransaction(result interface{}, method string, args } switch args[0].(type) { - case DeclareTxnV2, DeclareTxnV3: + case BroadcastDeclareTxnV2, BroadcastDeclareTxnV3: deadbeefFelt, err := utils.HexToFelt("0x41d1f5206ef58a443e7d3d1ca073171ec25fa75313394318fc83a074a6631c3") if err != nil { return err @@ -831,7 +831,7 @@ func mock_starknet_addDeployAccountTransaction(result interface{}, method string return errors.Wrap(errWrongArgs, fmt.Sprint("wrong number of args ", len(args))) } switch args[0].(type) { - case DeployAccountTxn, DeployAccountTxnV3: + case BroadcastDeployAccountTxn, BroadcastDeployAccountTxnV3: deadbeefFelt, err := utils.HexToFelt("0x32b272b6d0d584305a460197aa849b5c7a9a85903b66e9d3e1afa2427ef093e") if err != nil { diff --git a/rpc/types_broadcast_transaction.go b/rpc/types_broadcast_transaction.go index 46fbcc8d..167d28a0 100644 --- a/rpc/types_broadcast_transaction.go +++ b/rpc/types_broadcast_transaction.go @@ -23,7 +23,9 @@ var ( _ BroadcastInvokeTxnType = BroadcastInvokev3Txn{} ) -type BroadcastDeclareTxnType interface{} +type BroadcastDeclareTxnType interface { + GetContractClass() interface{} +} var ( _ BroadcastDeclareTxnType = BroadcastDeclareTxnV1{} @@ -31,7 +33,9 @@ var ( _ BroadcastDeclareTxnType = BroadcastDeclareTxnV3{} ) -type BroadcastAddDeployTxnType interface{} +type BroadcastAddDeployTxnType interface { + GetConstructorCalldata() []*felt.Felt +} var ( _ BroadcastAddDeployTxnType = BroadcastDeployAccountTxn{} @@ -72,6 +76,11 @@ type BroadcastDeclareTxnV1 struct { Nonce *felt.Felt `json:"nonce"` ContractClass DeprecatedContractClass `json:"contract_class"` } + +func (tx BroadcastDeclareTxnV1) GetContractClass() interface{} { + return tx.ContractClass +} + type BroadcastDeclareTxnV2 struct { Type TransactionType `json:"type"` // SenderAddress the address of the account contract sending the declaration transaction @@ -84,29 +93,31 @@ type BroadcastDeclareTxnV2 struct { ContractClass ContractClass `json:"contract_class"` } +func (tx BroadcastDeclareTxnV2) GetContractClass() interface{} { + return tx.ContractClass +} + type BroadcastDeclareTxnV3 struct { - Type TransactionType `json:"type"` - SenderAddress *felt.Felt `json:"sender_address"` - CompiledClassHash *felt.Felt `json:"compiled_class_hash"` - Version TransactionVersion `json:"version"` - Signature []*felt.Felt `json:"signature"` - Nonce *felt.Felt `json:"nonce"` - ContractClass *ContractClass `json:"contract_class"` - ResourceBounds ResourceBoundsMapping `json:"resource_bounds"` - Tip U64 `json:"tip"` - // The data needed to allow the paymaster to pay for the transaction in native tokens - PayMasterData []*felt.Felt `json:"paymaster_data"` - // The data needed to deploy the account contract from which this tx will be initiated - AccountDeploymentData *felt.Felt `json:"account_deployment_data"` - // The storage domain of the account's nonce (an account has a nonce per DA mode) - NonceDataMode DataAvailabilityMode `json:"nonce_data_availability_mode"` - // The storage domain of the account's balance from which fee will be charged - FeeMode DataAvailabilityMode `json:"fee_data_availability_mode"` + DeclareTxnV3 + ContractClass *ContractClass `json:"contract_class"` +} + +func (tx BroadcastDeclareTxnV3) GetContractClass() interface{} { + return *tx.ContractClass } type BroadcastDeployAccountTxn struct { DeployAccountTxn } + +func (tx BroadcastDeployAccountTxn) GetConstructorCalldata() []*felt.Felt { + return tx.ConstructorCalldata +} + type BroadcastDeployAccountTxnV3 struct { DeployAccountTxnV3 } + +func (tx BroadcastDeployAccountTxnV3) GetConstructorCalldata() []*felt.Felt { + return tx.ConstructorCalldata +} diff --git a/rpc/write.go b/rpc/write.go index f6b4ccdb..e91b3d52 100644 --- a/rpc/write.go +++ b/rpc/write.go @@ -39,14 +39,6 @@ func (provider *Provider) AddInvokeTransaction(ctx context.Context, invokeTxn Br // - *AddDeclareTransactionResponse: The response of submitting the declare transaction // - error: an error if any func (provider *Provider) AddDeclareTransaction(ctx context.Context, declareTransaction BroadcastDeclareTxnType) (*AddDeclareTransactionResponse, error) { - - switch txn := declareTransaction.(type) { - case DeclareTxnV2: - // DeclareTxnV2 should not have a populated class hash field. It is only needed for signing. - txn.ClassHash = nil - declareTransaction = txn - } - var result AddDeclareTransactionResponse if err := do(ctx, provider.c, "starknet_addDeclareTransaction", &result, declareTransaction); err != nil { return nil, tryUnwrapToRPCErr( diff --git a/rpc/write_test.go b/rpc/write_test.go index 0b3fd110..90e3038b 100644 --- a/rpc/write_test.go +++ b/rpc/write_test.go @@ -17,7 +17,7 @@ func TestDeclareTransaction(t *testing.T) { testConfig := beforeEach(t) type testSetType struct { - DeclareTx BroadcastAddDeployTxnType + DeclareTx BroadcastDeclareTxnType ExpectedResp AddDeclareTransactionResponse ExpectedError error } @@ -26,43 +26,44 @@ func TestDeclareTransaction(t *testing.T) { "mainnet": {}, "mock": { { - DeclareTx: DeclareTxnV2{}, + DeclareTx: BroadcastDeclareTxnV2{}, ExpectedResp: AddDeclareTransactionResponse{ TransactionHash: utils.TestHexToFelt(t, "0x41d1f5206ef58a443e7d3d1ca073171ec25fa75313394318fc83a074a6631c3")}, ExpectedError: nil, }, { - DeclareTx: DeclareTxnV3{ - Type: TransactionType_Declare, - Version: TransactionV3, - Signature: []*felt.Felt{}, - Nonce: utils.TestHexToFelt(t, "0x0"), - NonceDataMode: DAModeL1, - FeeMode: DAModeL1, - ResourceBounds: ResourceBoundsMapping{ - L1Gas: ResourceBounds{ - MaxAmount: "0x0", - MaxPricePerUnit: "0x0", - }, - L2Gas: ResourceBounds{ - MaxAmount: "0x0", - MaxPricePerUnit: "0x0", + DeclareTx: BroadcastDeclareTxnV3{ + DeclareTxnV3: DeclareTxnV3{ + Type: TransactionType_Declare, + Version: TransactionV3, + Signature: []*felt.Felt{}, + Nonce: utils.TestHexToFelt(t, "0x0"), + NonceDataMode: DAModeL1, + FeeMode: DAModeL1, + ResourceBounds: ResourceBoundsMapping{ + L1Gas: ResourceBounds{ + MaxAmount: "0x0", + MaxPricePerUnit: "0x0", + }, + L2Gas: ResourceBounds{ + MaxAmount: "0x0", + MaxPricePerUnit: "0x0", + }, }, - }, - Tip: "", - PayMasterData: []*felt.Felt{}, - SenderAddress: utils.TestHexToFelt(t, "0x0"), - CompiledClassHash: utils.TestHexToFelt(t, "0x0"), - ClassHash: utils.TestHexToFelt(t, "0x0"), - AccountDeploymentData: []*felt.Felt{}, - }, + Tip: "", + PayMasterData: []*felt.Felt{}, + SenderAddress: utils.TestHexToFelt(t, "0x0"), + CompiledClassHash: utils.TestHexToFelt(t, "0x0"), + ClassHash: utils.TestHexToFelt(t, "0x0"), + AccountDeploymentData: []*felt.Felt{}, + }}, ExpectedResp: AddDeclareTransactionResponse{ TransactionHash: utils.TestHexToFelt(t, "0x41d1f5206ef58a443e7d3d1ca073171ec25fa75313394318fc83a074a6631c3")}, ExpectedError: nil, }, }, "testnet": {{ - DeclareTx: DeclareTxnV1{}, + DeclareTx: BroadcastDeclareTxnV1{}, ExpectedResp: AddDeclareTransactionResponse{ TransactionHash: utils.TestHexToFelt(t, "0x55b094dc5c84c2042e067824f82da90988674314d37e45cb0032aca33d6e0b9")}, ExpectedError: errors.New("Invalid Params"), @@ -76,7 +77,7 @@ func TestDeclareTransaction(t *testing.T) { if err != nil { t.Fatal("should be able to read file", err) } - var declareTx AddDeclareTxnInput + var declareTx BroadcastDeclareTxnType // AddDeclareTxnInput require.Nil(t, json.Unmarshal(declareTxJSON, &declareTx), "Error unmarshalling decalreTx") test.DeclareTx = declareTx } @@ -193,7 +194,7 @@ func TestAddDeployAccountTansaction(t *testing.T) { "mainnet": {}, "mock": { { - DeployTx: DeployAccountTxn{}, + DeployTx: BroadcastDeployAccountTxn{DeployAccountTxn{}}, ExpectedResp: AddDeployAccountTransactionResponse{ TransactionHash: utils.TestHexToFelt(t, "0x32b272b6d0d584305a460197aa849b5c7a9a85903b66e9d3e1afa2427ef093e"), ContractAddress: utils.TestHexToFelt(t, "0x0"), @@ -201,34 +202,35 @@ func TestAddDeployAccountTansaction(t *testing.T) { ExpectedError: nil, }, { - DeployTx: DeployAccountTxnV3{ - Type: TransactionType_DeployAccount, - Version: TransactionV3, - ClassHash: utils.TestHexToFelt(t, "0x2338634f11772ea342365abd5be9d9dc8a6f44f159ad782fdebd3db5d969738"), - Signature: []*felt.Felt{ - utils.TestHexToFelt(t, "0x6d756e754793d828c6c1a89c13f7ec70dbd8837dfeea5028a673b80e0d6b4ec"), - utils.TestHexToFelt(t, "0x4daebba599f860daee8f6e100601d98873052e1c61530c630cc4375c6bd48e3"), - }, - Nonce: new(felt.Felt), - NonceDataMode: DAModeL1, - FeeMode: DAModeL1, - ResourceBounds: ResourceBoundsMapping{ - L1Gas: ResourceBounds{ - MaxAmount: "0x186a0", - MaxPricePerUnit: "0x5af3107a4000", + DeployTx: BroadcastDeployAccountTxnV3{ + DeployAccountTxnV3{ + Type: TransactionType_DeployAccount, + Version: TransactionV3, + ClassHash: utils.TestHexToFelt(t, "0x2338634f11772ea342365abd5be9d9dc8a6f44f159ad782fdebd3db5d969738"), + Signature: []*felt.Felt{ + utils.TestHexToFelt(t, "0x6d756e754793d828c6c1a89c13f7ec70dbd8837dfeea5028a673b80e0d6b4ec"), + utils.TestHexToFelt(t, "0x4daebba599f860daee8f6e100601d98873052e1c61530c630cc4375c6bd48e3"), + }, + Nonce: new(felt.Felt), + NonceDataMode: DAModeL1, + FeeMode: DAModeL1, + ResourceBounds: ResourceBoundsMapping{ + L1Gas: ResourceBounds{ + MaxAmount: "0x186a0", + MaxPricePerUnit: "0x5af3107a4000", + }, + L2Gas: ResourceBounds{ + MaxAmount: "", + MaxPricePerUnit: "", + }, }, - L2Gas: ResourceBounds{ - MaxAmount: "", - MaxPricePerUnit: "", + Tip: "", + PayMasterData: []*felt.Felt{}, + ContractAddressSalt: new(felt.Felt), + ConstructorCalldata: []*felt.Felt{ + utils.TestHexToFelt(t, "0x5cd65f3d7daea6c63939d659b8473ea0c5cd81576035a4d34e52fb06840196c"), }, - }, - Tip: "", - PayMasterData: []*felt.Felt{}, - ContractAddressSalt: new(felt.Felt), - ConstructorCalldata: []*felt.Felt{ - utils.TestHexToFelt(t, "0x5cd65f3d7daea6c63939d659b8473ea0c5cd81576035a4d34e52fb06840196c"), - }, - }, + }}, ExpectedResp: AddDeployAccountTransactionResponse{ TransactionHash: utils.TestHexToFelt(t, "0x32b272b6d0d584305a460197aa849b5c7a9a85903b66e9d3e1afa2427ef093e"), ContractAddress: utils.TestHexToFelt(t, "0x0")},