Skip to content

Commit

Permalink
Merge branch 'main' into thiagodeev/upgrade-remaining-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagodeev committed Jul 5, 2024
2 parents 9ddc944 + 9d42a78 commit 189ee0d
Show file tree
Hide file tree
Showing 23 changed files with 216 additions and 193 deletions.
53 changes: 28 additions & 25 deletions account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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")
})
Expand Down Expand Up @@ -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
}
Expand All @@ -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"),
Expand All @@ -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"),
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions contracts/contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 10 additions & 9 deletions examples/deployContractUDC/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
19 changes: 10 additions & 9 deletions examples/simpleInvoke/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion hash/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions rpc/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion rpc/call_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion rpc/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion rpc/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"testing"

"github.com/test-go/testify/require"
"github.com/stretchr/testify/require"
)

func TestRPCError(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion rpc/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions rpc/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion rpc/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion rpc/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion rpc/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rpc/types_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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"
)

// TestBlockID_Marshal tests the MarshalJSON method of the BlockID struct.
Expand Down
Loading

0 comments on commit 189ee0d

Please sign in to comment.