Skip to content

Commit

Permalink
Merge pull request #226 from NethermindEth/FixRPCv02Tests
Browse files Browse the repository at this point in the history
Fix rpcv02 tests
  • Loading branch information
cicr99 authored Jul 25, 2023
2 parents 48e653e + 90e0706 commit a4cfd1c
Show file tree
Hide file tree
Showing 35 changed files with 6,921 additions and 705 deletions.
33 changes: 10 additions & 23 deletions .github/workflows/rpcv02.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,29 @@ jobs:
- name: wait for devnet to be up...
run: ./.bin/devnet.sh

- name: Test contracts deployment and execute
run: echo "skip for now"
# run: cd contracts && go test -env devnet -v -run "^TestRPCv02" .

- name: Preinstall RPC v0.2 contracts on devnet
run: echo "skip for now"
# run: cd rpcv02 && go test -timeout 600s -v -env devnet -run TestDeployTransaction . && sleep 5
env:
TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }}
INTEGRATION_BASE: "http://localhost:5050/rpc"

- name: Test Accounts (starknet.go) on devnet
run: echo "skip for now"
# run: go test -timeout 600s -v -env devnet -run "^(TestGateway|TestRPCv02|TestGeneral)" .
# Test rpc on devnet
- name: Test RPC v0.2 on devnet
run: cd rpcv02 && go test -timeout 600s -v -env devnet .
env:
TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }}
INTEGRATION_BASE: "http://localhost:5050/rpc"

# Test rpc on mock
- name: Test RPC v0.2 with mocks
run: cd rpcv02 && go test -v .

- name: Test RPC v0.2 on devnet
run: echo "skip for now"
# run: cd rpcv02 && go test -timeout 600s -v -env devnet .
env:
TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }}
INTEGRATION_BASE: "http://localhost:5050/rpc"

# Test rpc on testnet
- name: Test RPC v0.2 on testnet
run: cd rpcv02 && go test -timeout 1200s -v -env testnet .
run: echo "Skip for now - need public endpoint that follows rpc spec"
#run: cd rpcv02 && go test -timeout 1200s -v -env testnet .
env:
TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }}
INTEGRATION_BASE: "https://starknet-goerli.cartridge.gg/"

# Test rpc on mainnet
- name: Test RPC v0.2 with mainnet
run: cd rpcv02 && go test -timeout 600s -v -env mainnet .
run: echo "Skip for now - need public endpoint that follows rpc spec"
#run: cd rpcv02 && go test -timeout 600s -v -env mainnet .
env:
TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }}
INTEGRATION_BASE: "https://starknet.cartridge.gg/"
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ starknet.go
vendor/
.env*
!.env.template
rpc*/.env.mainnet
rpc*/.env.testnet

*.txt

Expand All @@ -16,4 +18,4 @@ examples/**/*.sum

*/**/*abi.json

.idea/
.idea/
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}"
}
]
}
23 changes: 12 additions & 11 deletions accountgw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/NethermindEth/starknet.go/types"
"github.com/NethermindEth/starknet.go/utils"
)

type TestAccountType struct {
Expand All @@ -26,22 +27,22 @@ func TestGatewayAccount_EstimateAndExecute(t *testing.T) {
testSet := map[string][]testSetType{
"devnet": {{
ExecuteCalls: []types.FunctionCall{{
EntryPointSelector: "increment",
ContractAddress: types.StrToFelt(testConfig.CounterAddress),
EntryPointSelector: types.GetSelectorFromNameFelt("increment"),
ContractAddress: utils.TestHexToFelt(t, testConfig.CounterAddress),
}},
QueryCall: types.FunctionCall{
EntryPointSelector: "get_count",
ContractAddress: types.StrToFelt(testConfig.CounterAddress),
EntryPointSelector: types.GetSelectorFromNameFelt("get_count"),
ContractAddress: utils.TestHexToFelt(t, testConfig.CounterAddress),
},
}},
"testnet": {{
ExecuteCalls: []types.FunctionCall{{
EntryPointSelector: "increment",
ContractAddress: types.StrToFelt(testConfig.CounterAddress),
EntryPointSelector: types.GetSelectorFromNameFelt("increment"),
ContractAddress: utils.TestHexToFelt(t, testConfig.CounterAddress),
}},
QueryCall: types.FunctionCall{
EntryPointSelector: "get_count",
ContractAddress: types.StrToFelt(testConfig.CounterAddress),
EntryPointSelector: types.GetSelectorFromNameFelt("get_count"),
ContractAddress: utils.TestHexToFelt(t, testConfig.CounterAddress),
},
}},
}[testEnv]
Expand All @@ -53,8 +54,8 @@ func TestGatewayAccount_EstimateAndExecute(t *testing.T) {
k := types.SNValToBN(testConfig.AccountPrivateKey)
ks.Put(fakeSenderAddress, k)
account, err := NewGatewayAccount(
types.StrToFelt(fakeSenderAddress),
types.StrToFelt(testConfig.AccountAddress),
utils.TestHexToFelt(t, fakeSenderAddress),
utils.TestHexToFelt(t, testConfig.AccountAddress),
ks,
testConfig.client,
AccountVersion1)
Expand All @@ -77,7 +78,7 @@ func TestGatewayAccount_EstimateAndExecute(t *testing.T) {
t.Fatal("should succeed with Execute, instead:", err)
}
fmt.Printf("Execute txHash: %v\n", tx.TransactionHash)
_, state, err := testConfig.client.WaitForTransaction(ctx, tx.TransactionHash, 3, 10)
_, state, err := testConfig.client.WaitForTransaction(ctx, tx.TransactionHash.String(), 3, 10)
if err != nil {
t.Fatal("should succeed with Execute, instead:", err)
}
Expand Down
24 changes: 13 additions & 11 deletions accountrpcv02_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"testing"
"time"

"github.com/NethermindEth/juno/core/felt"
rpc "github.com/NethermindEth/starknet.go/rpcv02"
"github.com/NethermindEth/starknet.go/types"
"github.com/NethermindEth/starknet.go/utils"
)

// TestAccountNonce tests the account Nonce
Expand Down Expand Up @@ -47,7 +49,7 @@ func TestRPCv02Account_Nonce(t *testing.T) {
fakeSenderAddress := pk
k := types.SNValToBN(pk)
ks.Put(fakeSenderAddress, k)
account, err := NewRPCAccount(types.StrToFelt(fakeSenderAddress), types.StrToFelt(test.Address), ks, testConfig.providerv02)
account, err := NewRPCAccount(utils.TestHexToFelt(t, fakeSenderAddress), utils.TestHexToFelt(t, test.Address), ks, testConfig.providerv02)
if err != nil {
t.Fatal(err)
}
Expand All @@ -74,9 +76,9 @@ func TestRPCv02Account_EstimateFee(t *testing.T) {
Address: DevNetAccount032Address,
PrivateKeyEnvVar: "TESTNET_ACCOUNT_PRIVATE_KEY",
Call: types.FunctionCall{
ContractAddress: types.StrToFelt("0x07704fb2d72fcdae1e6f658ef8521415070a01a3bd3cc5788f7b082126922b7b"),
EntryPointSelector: "increment",
Calldata: []string{},
ContractAddress: utils.TestHexToFelt(t, "0x07704fb2d72fcdae1e6f658ef8521415070a01a3bd3cc5788f7b082126922b7b"),
EntryPointSelector: types.GetSelectorFromNameFelt("increment"),
Calldata: []*felt.Felt{},
},
},
},
Expand All @@ -85,9 +87,9 @@ func TestRPCv02Account_EstimateFee(t *testing.T) {
Address: TestNetAccount032Address,
PrivateKeyEnvVar: "TESTNET_ACCOUNT_PRIVATE_KEY",
Call: types.FunctionCall{
ContractAddress: types.StrToFelt("0x357b37bf12f59dd04c4da4933dcadf4a104e158365886d64ca0e554ada68fef"),
EntryPointSelector: "increment",
Calldata: []string{},
ContractAddress: utils.TestHexToFelt(t, "0x357b37bf12f59dd04c4da4933dcadf4a104e158365886d64ca0e554ada68fef"),
EntryPointSelector: types.GetSelectorFromNameFelt("increment"),
Calldata: []*felt.Felt{},
},
},
},
Expand All @@ -102,7 +104,7 @@ func TestRPCv02Account_EstimateFee(t *testing.T) {
fakeSenderAddress := pk
k := types.SNValToBN(pk)
ks.Put(fakeSenderAddress, k)
account, err := NewRPCAccount(types.StrToFelt(fakeSenderAddress), types.StrToFelt(test.Address), ks, testConfig.providerv02)
account, err := NewRPCAccount(utils.TestHexToFelt(t, fakeSenderAddress), utils.TestHexToFelt(t, test.Address), ks, testConfig.providerv02)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -140,7 +142,7 @@ func TestRPCv02Account_Execute(t *testing.T) {
fakeSenderAddress := pk
k := types.SNValToBN(pk)
ks.Put(fakeSenderAddress, k)
account, err := NewRPCAccount(types.StrToFelt(fakeSenderAddress), types.StrToFelt(test.Address), ks, testConfig.providerv02)
account, err := NewRPCAccount(utils.TestHexToFelt(t, fakeSenderAddress), utils.TestHexToFelt(t, test.Address), ks, testConfig.providerv02)
if err != nil {
t.Fatal(err)
}
Expand All @@ -149,13 +151,13 @@ func TestRPCv02Account_Execute(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if !strings.HasPrefix(execute.TransactionHash, "0x") {
if !strings.HasPrefix(execute.TransactionHash.String(), "0x") {
t.Fatal("TransactionHash start with 0x, instead:", execute.TransactionHash)
}
fmt.Println("transaction_hash:", execute.TransactionHash)
ctx, cancel := context.WithTimeout(ctx, 600*time.Second)
defer cancel()
status, err := account.rpcv02.WaitForTransaction(ctx, types.StrToFelt(execute.TransactionHash), 8*time.Second)
status, err := account.rpcv02.WaitForTransaction(ctx, execute.TransactionHash, 8*time.Second)
if err != nil {
t.Fatal("declare should succeed, instead:", err)
}
Expand Down
16 changes: 8 additions & 8 deletions contracts/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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} {
Expand All @@ -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,
Expand All @@ -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} {
Expand All @@ -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,
Expand Down
Loading

0 comments on commit a4cfd1c

Please sign in to comment.