diff --git a/contracts/account_test.go b/contracts/account_test.go index e725dd9b..19eda9e5 100644 --- a/contracts/account_test.go +++ b/contracts/account_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/NethermindEth/starknet.go" + starknetgo "github.com/NethermindEth/starknet.go" "github.com/NethermindEth/starknet.go/artifacts" "github.com/joho/godotenv" ) @@ -19,11 +19,11 @@ func TestGateway_InstallAccounts(t *testing.T) { type TestCase struct { privateKey string CompiledContract artifacts.CompiledContract - providerType starknet.go.ProviderType + providerType starknetgo.ProviderType } devnet := []TestCase{} - for _, provider := range []starknet.go.ProviderType{starknet.go.ProviderGateway} { + for _, provider := range []starknetgo.ProviderType{starknetgo.ProviderGateway} { for _, version := range []string{"v1"} { for _, proxy := range []bool{false, true} { for _, plugin := range []bool{false, true} { @@ -47,7 +47,7 @@ func TestGateway_InstallAccounts(t *testing.T) { var accountManager *AccountManager var err error switch test.providerType { - case starknet.go.ProviderGateway: + case starknetgo.ProviderGateway: accountManager, err = InstallAndWaitForAccount( ctx, testConfiguration.gateway, @@ -71,11 +71,11 @@ func TestRPCv02_InstallAccounts(t *testing.T) { type TestCase struct { privateKey string CompiledContract artifacts.CompiledContract - providerType starknet.go.ProviderType + providerType starknetgo.ProviderType } devnet := []TestCase{} - for _, provider := range []starknet.go.ProviderType{starknet.go.ProviderRPCv02} { + for _, provider := range []starknetgo.ProviderType{starknetgo.ProviderRPCv02} { for _, version := range []string{"v1"} { for _, proxy := range []bool{false, true} { for _, plugin := range []bool{false, true} { @@ -99,14 +99,14 @@ func TestRPCv02_InstallAccounts(t *testing.T) { var accountManager *AccountManager var err error switch test.providerType { - case starknet.go.ProviderRPCv02: + case starknetgo.ProviderRPCv02: accountManager, err = InstallAndWaitForAccount( ctx, testConfiguration.rpcv02, privateKey, test.CompiledContract, ) - case starknet.go.ProviderGateway: + case starknetgo.ProviderGateway: accountManager, err = InstallAndWaitForAccount( ctx, testConfiguration.gateway, diff --git a/contracts/contracts_test.go b/contracts/contracts_test.go index 20c358da..c92d185d 100644 --- a/contracts/contracts_test.go +++ b/contracts/contracts_test.go @@ -7,10 +7,12 @@ import ( "testing" "time" - "github.com/NethermindEth/starknet.go" + "github.com/NethermindEth/juno/core/felt" + starknetgo "github.com/NethermindEth/starknet.go" "github.com/NethermindEth/starknet.go/artifacts" devtest "github.com/NethermindEth/starknet.go/test" "github.com/NethermindEth/starknet.go/types" + "github.com/NethermindEth/starknet.go/utils" "github.com/joho/godotenv" ) @@ -19,7 +21,7 @@ func TestGateway_InstallCounter(t *testing.T) { testConfiguration := beforeEach(t) type TestCase struct { - providerType starknet.go.ProviderType + providerType starknetgo.ProviderType CompiledClass []byte Salt string Inputs []string @@ -28,7 +30,7 @@ func TestGateway_InstallCounter(t *testing.T) { TestCases := map[string][]TestCase{ "devnet": { { - providerType: starknet.go.ProviderGateway, + providerType: starknetgo.ProviderGateway, CompiledClass: artifacts.CounterCompiled, Salt: "0x0", Inputs: []string{}, @@ -42,7 +44,7 @@ func TestGateway_InstallCounter(t *testing.T) { var err error var tx *DeployOutput switch test.providerType { - case starknet.go.ProviderGateway: + case starknetgo.ProviderGateway: provider := GatewayProvider(*testConfiguration.gateway) tx, err = provider.deployAndWaitNoWallet(ctx, test.CompiledClass, test.Salt, test.Inputs) default: @@ -60,7 +62,7 @@ func TestRPCv02_InstallCounter(t *testing.T) { testConfiguration := beforeEach(t) type TestCase struct { - providerType starknet.go.ProviderType + providerType starknetgo.ProviderType CompiledClass []byte Salt string Inputs []string @@ -69,7 +71,7 @@ func TestRPCv02_InstallCounter(t *testing.T) { TestCases := map[string][]TestCase{ "devnet": { { - providerType: starknet.go.ProviderRPCv02, + providerType: starknetgo.ProviderRPCv02, CompiledClass: artifacts.CounterCompiled, Salt: "0x01", Inputs: []string{}, @@ -83,7 +85,7 @@ func TestRPCv02_InstallCounter(t *testing.T) { var err error var tx *DeployOutput switch test.providerType { - case starknet.go.ProviderRPCv02: + case starknetgo.ProviderRPCv02: provider := RPCv02Provider(*testConfiguration.rpcv02) tx, err = provider.deployAndWaitWithWallet(ctx, test.CompiledClass, test.Salt, test.Inputs) default: @@ -102,7 +104,7 @@ func TestGateway_LoadAndExecuteCounter(t *testing.T) { type TestCase struct { privateKey string - providerType starknet.go.ProviderType + providerType starknetgo.ProviderType accountContract artifacts.CompiledContract } @@ -110,7 +112,7 @@ func TestGateway_LoadAndExecuteCounter(t *testing.T) { "devnet": { { privateKey: "0x01", - providerType: starknet.go.ProviderGateway, + providerType: starknetgo.ProviderGateway, accountContract: artifacts.AccountContracts[ACCOUNT_VERSION1][false][false], }, }, @@ -121,16 +123,16 @@ func TestGateway_LoadAndExecuteCounter(t *testing.T) { defer cancel() var err error var counterTransaction *DeployOutput - var account *starknet.go.Account + var account *starknetgo.Account // shim a keystore into existing tests. // use string representation of the PK as a fake sender address for the keystore - ks := starknet.go.NewMemKeystore() + ks := starknetgo.NewMemKeystore() fakeSenderAddress := test.privateKey k := types.SNValToBN(test.privateKey) ks.Put(fakeSenderAddress, k) switch test.providerType { - case starknet.go.ProviderGateway: + case starknetgo.ProviderGateway: pk, _ := big.NewInt(0).SetString(test.privateKey, 0) accountManager, err := InstallAndWaitForAccount( ctx, @@ -141,7 +143,7 @@ func TestGateway_LoadAndExecuteCounter(t *testing.T) { if err != nil { t.Fatal("error deploying account", err) } - mint, err := devtest.NewDevNet().Mint(types.StrToFelt(accountManager.AccountAddress), big.NewInt(int64(1000000000000000000))) + mint, err := devtest.NewDevNet().Mint(utils.TestHexToFelt(t, accountManager.AccountAddress), big.NewInt(int64(1000000000000000000))) if err != nil { t.Fatal("error deploying account", err) } @@ -152,14 +154,15 @@ func TestGateway_LoadAndExecuteCounter(t *testing.T) { t.Fatal("should succeed, instead", err) } fmt.Println("deployment transaction", counterTransaction.TransactionHash) - account, err = starknet.go.NewGatewayAccount(types.StrToFelt(fakeSenderAddress), types.StrToFelt(accountManager.AccountAddress), ks, testConfiguration.gateway, starknet.go.AccountVersion1) + + account, err = starknetgo.NewGatewayAccount(utils.TestHexToFelt(t, fakeSenderAddress), utils.TestHexToFelt(t, accountManager.AccountAddress), ks, testConfiguration.gateway, starknetgo.AccountVersion1) if err != nil { t.Fatal("should succeed, instead", err) } default: t.Fatal("unsupported client type", test.providerType) } - tx, err := account.Execute(ctx, []types.FunctionCall{{ContractAddress: types.StrToFelt(counterTransaction.ContractAddress), EntryPointSelector: "increment", Calldata: []string{}}}, types.ExecuteDetails{}) + tx, err := account.Execute(ctx, []types.FunctionCall{{ContractAddress: utils.TestHexToFelt(t, counterTransaction.ContractAddress), EntryPointSelector: types.GetSelectorFromNameFelt("increment"), Calldata: []*felt.Felt{}}}, types.ExecuteDetails{}) if err != nil { t.Fatal("should succeed, instead", err) } @@ -173,7 +176,7 @@ func TestRPCv02_LoadAndExecuteCounter(t *testing.T) { type TestCase struct { privateKey string - providerType starknet.go.ProviderType + providerType starknetgo.ProviderType accountContract artifacts.CompiledContract } @@ -181,7 +184,7 @@ func TestRPCv02_LoadAndExecuteCounter(t *testing.T) { "devnet": { { privateKey: "0xe3e70682c2094cac629f6fbed82c07cd", - providerType: starknet.go.ProviderRPCv02, + providerType: starknetgo.ProviderRPCv02, accountContract: artifacts.AccountContracts[ACCOUNT_VERSION1][false][false], }, }, @@ -192,14 +195,14 @@ func TestRPCv02_LoadAndExecuteCounter(t *testing.T) { defer cancel() var err error var counterTransaction *DeployOutput - var account *starknet.go.Account - ks := starknet.go.NewMemKeystore() + var account *starknetgo.Account + ks := starknetgo.NewMemKeystore() fakeSenderAddress := test.privateKey k := types.SNValToBN(test.privateKey) ks.Put(fakeSenderAddress, k) switch test.providerType { - case starknet.go.ProviderRPCv02: + case starknetgo.ProviderRPCv02: pk, _ := big.NewInt(0).SetString(test.privateKey, 0) fmt.Println("befor") accountManager := &AccountManager{} @@ -213,7 +216,7 @@ func TestRPCv02_LoadAndExecuteCounter(t *testing.T) { t.Fatal("error deploying account", err) } fmt.Println("after") - mint, err := devtest.NewDevNet().Mint(types.StrToFelt(accountManager.AccountAddress), big.NewInt(int64(1000000000000000000))) + mint, err := devtest.NewDevNet().Mint(utils.TestHexToFelt(t, accountManager.AccountAddress), big.NewInt(int64(1000000000000000000))) if err != nil { t.Fatal("error deploying account", err) } @@ -224,14 +227,14 @@ func TestRPCv02_LoadAndExecuteCounter(t *testing.T) { t.Fatal("should succeed, instead", err) } fmt.Println("deployment transaction", counterTransaction.TransactionHash) - account, err = starknet.go.NewRPCAccount(types.StrToFelt(fakeSenderAddress), types.StrToFelt(accountManager.AccountAddress), ks, testConfiguration.rpcv02, starknet.go.AccountVersion1) + account, err = starknetgo.NewRPCAccount(utils.TestHexToFelt(t, fakeSenderAddress), utils.TestHexToFelt(t, accountManager.AccountAddress), ks, testConfiguration.rpcv02, starknetgo.AccountVersion1) if err != nil { t.Fatal("should succeed, instead", err) } default: t.Fatal("unsupported client type", test.providerType) } - tx, err := account.Execute(ctx, []types.FunctionCall{{ContractAddress: types.StrToFelt(counterTransaction.ContractAddress), EntryPointSelector: "increment", Calldata: []string{}}}, types.ExecuteDetails{}) + tx, err := account.Execute(ctx, []types.FunctionCall{{ContractAddress: utils.TestHexToFelt(t, counterTransaction.ContractAddress), EntryPointSelector: types.GetSelectorFromNameFelt("increment"), Calldata: []*felt.Felt{}}}, types.ExecuteDetails{}) if err != nil { t.Fatal("should succeed, instead", err) } diff --git a/go.mod b/go.mod index 06a13d56..b2569cb6 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/ethereum/go-ethereum v1.10.26 github.com/joho/godotenv v1.4.0 github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249 + github.com/test-go/testify v1.1.4 github.com/urfave/cli/v2 v2.10.2 golang.org/x/crypto v0.2.0 ) @@ -16,18 +17,22 @@ require ( github.com/bits-and-blooms/bitset v1.7.0 // indirect github.com/consensys/gnark-crypto v0.11.0 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/deckarep/golang-set v1.8.0 // indirect github.com/fxamacker/cbor/v2 v2.4.0 // indirect github.com/go-ole/go-ole v1.2.1 // indirect github.com/go-stack/stack v1.8.0 // indirect github.com/gorilla/websocket v1.4.2 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect + github.com/stretchr/testify v1.8.1 // indirect github.com/tklauser/go-sysconf v0.3.5 // indirect github.com/tklauser/numcpus v0.2.2 // indirect github.com/x448/float16 v0.8.4 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) require ( diff --git a/go.sum b/go.sum index e3b6fcf5..bd0a8883 100644 --- a/go.sum +++ b/go.sum @@ -8,7 +8,9 @@ github.com/consensys/gnark-crypto v0.11.0 h1:QqzHQlwEqlQr5jfWblGDkwlKHpT+4QodYqq github.com/consensys/gnark-crypto v0.11.0/go.mod h1:Iq/P3HHl0ElSjsg2E1gsMwhAyxnxoKK5nVyZKd+/KhU= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4= github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo= github.com/ethereum/go-ethereum v1.10.26 h1:i/7d9RBBwiXCEuyduBQzJw/mKmnvzsN14jqBmytw72s= @@ -32,11 +34,20 @@ github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7 github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249 h1:NHrXEjTNQY7P0Zfx1aMrNhpgxHmow66XQtm0aQLY0AE= github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249/go.mod h1:mpRZBD8SJ55OIICQ3iWH0Yz3cjzA61JdqMLoWXeB2+8= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +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.5 h1:uu3Xl4nkLzQfXNsWn15rPc/HQCJKObbt1dKJeWp3vU4= github.com/tklauser/go-sysconf v0.3.5/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITnppBXY/rYEFI= github.com/tklauser/numcpus v0.2.2 h1:oyhllyrScuYI6g+h/zUvNXNp1wy7x8qQy3t/piefldA= @@ -54,6 +65,10 @@ golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df h1:5Pf6pFKu98ODmgnpvkJ3kFUOQGGLIzLIkbzUHp47618= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/utils/Test.go b/utils/Test.go new file mode 100644 index 00000000..23c8645c --- /dev/null +++ b/utils/Test.go @@ -0,0 +1,30 @@ +package utils + +import ( + "math/big" + "testing" + + "github.com/NethermindEth/juno/core/felt" + "github.com/test-go/testify/require" +) + +func TestHexToFelt(t testing.TB, hex string) *felt.Felt { + t.Helper() + f, err := HexToFelt(hex) + require.NoError(t, err) + return f +} + +func TestBigIntToFelt(t testing.TB, big *big.Int) *felt.Felt { + t.Helper() + felt, err := BigIntToFelt(big) + require.NoError(t, err) + return felt +} + +func TestHexArrToFelt(t testing.TB, hexArr []string) []*felt.Felt { + t.Helper() + feltArr, err := HexArrToFelt(hexArr) + require.NoError(t, err) + return feltArr +}