Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename rpcv02 package to rpc #253

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 3 additions & 30 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,46 +31,19 @@ jobs:
run: ./.bin/devnet.sh

- name: Test contracts deployment and execute
run: cd contracts && go test -env devnet -v -run "^(TestGateway|TestRPCv01)" .

- name: Test RPC v0.1 with mocks
run: cd rpcv01 && go test -v .

- name: Preinstall RPC v0.1 contracts on devnet
run: cd rpcv01 && 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"
run: cd contracts && go test -env devnet -v -run "^(TestGateway|TestRPC)" .

- name: Test Accounts (starknet.go) on devnet
run: go test -timeout 600s -v -env devnet -run "^(TestGateway|TestRPCv01|TestGeneral)" .
env:
TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }}
INTEGRATION_BASE: "http://localhost:5050/rpc"

- name: Test RPC v0.1 on devnet
run: cd rpcv01 && go test -timeout 600s -v -env devnet .
run: go test -timeout 600s -v -env devnet -run "^(TestGateway|TestRPC|TestGeneral)" .
env:
TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }}
INTEGRATION_BASE: "http://localhost:5050/rpc"

- name: Test sessionkey on devnet
run: cd plugins/xsessions && ./sessionkey.sh

- name: Test RPC v0.1 on testnet
run: cd rpcv01 && go test -timeout 1200s -v -env testnet .
env:
TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }}
INTEGRATION_BASE: "https://starknet-goerli.cartridge.gg/rpc/v0.1"

- name: Test RPC v0.1 with mainnet
run: cd rpcv01 && go test -timeout 600s -v -env mainnet .
env:
TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }}
INTEGRATION_BASE: "https://starknet.cartridge.gg/rpc/v0.1"

- name: Test Gateway with testnet
run: cd gateway && go test -v -env testnet .

- name: Test Gateway with devnet
run: cd gateway && go test -v -env devnet .
run: cd gateway && go test -v -env devnet .
18 changes: 9 additions & 9 deletions .github/workflows/rpcv02.yml → .github/workflows/test_rpc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: rpcv02
name: rpc

on:
push:
Expand Down Expand Up @@ -29,28 +29,28 @@ jobs:
run: ./.bin/devnet.sh

# Test rpc on devnet
- name: Test RPC v0.2 on devnet
run: cd rpcv02 && go test -timeout 600s -v -env devnet .
- name: Test RPC on devnet
run: cd rpc && 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 with mocks
run: cd rpc && go test -v .

# Test rpc on testnet
- name: Test RPC v0.2 on testnet
- name: Test RPC on testnet
run: echo "Skip for now - need public endpoint that follows rpc spec"
#run: cd rpcv02 && go test -timeout 1200s -v -env testnet .
#run: cd rpc && 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
- name: Test RPC with mainnet
run: echo "Skip for now - need public endpoint that follows rpc spec"
#run: cd rpcv02 && go test -timeout 600s -v -env mainnet .
#run: cd rpc && go test -timeout 600s -v -env mainnet .
env:
TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }}
INTEGRATION_BASE: "https://starknet.cartridge.gg/"
68 changes: 34 additions & 34 deletions account.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/gateway"
"github.com/NethermindEth/starknet.go/rpcv02"
"github.com/NethermindEth/starknet.go/rpc"
"github.com/NethermindEth/starknet.go/types"
"github.com/NethermindEth/starknet.go/utils"
)
Expand All @@ -31,7 +31,7 @@ type account interface {
Nonce(ctx context.Context) (*big.Int, error)
EstimateFee(ctx context.Context, calls []types.FunctionCall, details types.ExecuteDetails) (*types.FeeEstimate, error)
Execute(ctx context.Context, calls []types.FunctionCall, details types.ExecuteDetails) (*types.AddInvokeTransactionOutput, error)
Declare(ctx context.Context, classHash string, contract rpcv02.ContractClass, details types.ExecuteDetails) (types.AddDeclareResponse, error)
Declare(ctx context.Context, classHash string, contract rpc.ContractClass, details types.ExecuteDetails) (types.AddDeclareResponse, error)
Deploy(ctx context.Context, classHash string, details types.ExecuteDetails) (*types.AddDeployResponse, error)
}

Expand All @@ -44,12 +44,12 @@ type AccountPlugin interface {
type ProviderType string

const (
ProviderRPCv02 ProviderType = "rpcv02"
ProviderRPC ProviderType = "rpc"
ProviderGateway ProviderType = "gateway"
)

type Account struct {
rpcv02 *rpcv02.Provider
rpc *rpc.Provider
sequencer *gateway.GatewayProvider
provider ProviderType
chainId string
Expand Down Expand Up @@ -108,20 +108,20 @@ func newAccount(sender, address *felt.Felt, ks Keystore, options ...AccountOptio

func setAccountProvider(account *Account, provider interface{}) error {
switch p := provider.(type) {
case *rpcv02.Provider:
case *rpc.Provider:
chainID, err := p.ChainID(context.Background())
if err != nil {
return err
}
account.chainId = chainID
account.provider = ProviderRPCv02
account.rpcv02 = p
account.provider = ProviderRPC
account.rpc = p
return nil
}
return errors.New("unsupported provider")
}

func NewRPCAccount[Provider *rpcv02.Provider](sender, address *felt.Felt, ks Keystore, provider Provider, options ...AccountOptionFunc) (*Account, error) {
func NewRPCAccount[Provider *rpc.Provider](sender, address *felt.Felt, ks Keystore, provider Provider, options ...AccountOptionFunc) (*Account, error) {
account, err := newAccount(sender, address, ks, options...)
if err != nil {
return nil, err
Expand All @@ -147,17 +147,17 @@ func NewGatewayAccount(sender, address *felt.Felt, ks Keystore, provider *gatewa

func (account *Account) Call(ctx context.Context, call types.FunctionCall) ([]string, error) {
switch account.provider {
case ProviderRPCv02:
if account.rpcv02 == nil {
case ProviderRPC:
if account.rpc == nil {
return nil, ErrUnsupportedAccount
}
return account.rpcv02.Call(
return account.rpc.Call(
ctx,
rpcv02.FunctionCall{
rpc.FunctionCall{
ContractAddress: call.ContractAddress,
EntryPointSelector: call.EntryPointSelector,
Calldata: call.Calldata},
rpcv02.WithBlockTag("latest"))
rpc.WithBlockTag("latest"))
case ProviderGateway:
if account.sequencer == nil {
return nil, ErrUnsupportedAccount
Expand Down Expand Up @@ -235,10 +235,10 @@ func (account *Account) Nonce(ctx context.Context) (*big.Int, error) {
switch account.version {
case 1:
switch account.provider {
case ProviderRPCv02:
nonce, err := account.rpcv02.Nonce(
case ProviderRPC:
nonce, err := account.rpc.Nonce(
ctx,
rpcv02.WithBlockTag("latest"),
rpc.WithBlockTag("latest"),
account.AccountAddress,
)
if err != nil {
Expand All @@ -256,7 +256,7 @@ func (account *Account) Nonce(ctx context.Context) (*big.Int, error) {
return nil, fmt.Errorf("version %d unsupported", account.version)
}

func (account *Account) prepFunctionInvokeRPCv02(ctx context.Context, messageType string, calls []types.FunctionCall, details types.ExecuteDetails) (*rpcv02.BroadcastedInvokeV1Transaction, error) {
func (account *Account) prepFunctionInvokeRPC(ctx context.Context, messageType string, calls []types.FunctionCall, details types.ExecuteDetails) (*rpc.BroadcastedInvokeV1Transaction, error) {
if messageType != "invoke" && messageType != "estimate" {
return nil, errors.New("unsupported message type")
}
Expand All @@ -281,7 +281,7 @@ func (account *Account) prepFunctionInvokeRPCv02(ctx context.Context, messageTyp
}

// starknet.go currently only supports V1
version := rpcv02.TransactionV1
version := rpc.TransactionV1

var txHash *big.Int
switch messageType {
Expand All @@ -300,7 +300,7 @@ func (account *Account) prepFunctionInvokeRPCv02(ctx context.Context, messageTyp
case "estimate":
if account.version == 1 {
// version, _ = big.NewInt(0).SetString("0x100000000000000000000000000000001", 0)
version = rpcv02.TransactionV1
version = rpc.TransactionV1
}
versionBig, err := version.BigInt()
if err != nil {
Expand Down Expand Up @@ -347,8 +347,8 @@ func (account *Account) prepFunctionInvokeRPCv02(ctx context.Context, messageTyp
if err != nil {
return nil, err
}
return &rpcv02.BroadcastedInvokeV1Transaction{
BroadcastedTxnCommonProperties: rpcv02.BroadcastedTxnCommonProperties{
return &rpc.BroadcastedInvokeV1Transaction{
BroadcastedTxnCommonProperties: rpc.BroadcastedTxnCommonProperties{
MaxFee: maxFeeFelt,
Version: version,
Signature: []*felt.Felt{s1Felt, s2Felt},
Expand Down Expand Up @@ -440,24 +440,24 @@ func (account *Account) prepFunctionInvoke(ctx context.Context, messageType stri
func (account *Account) EstimateFee(ctx context.Context, calls []types.FunctionCall, details types.ExecuteDetails) (*types.FeeEstimate, error) {

switch account.provider {
case ProviderRPCv02:
call, err := account.prepFunctionInvokeRPCv02(ctx, "estimate", calls, details)
case ProviderRPC:
call, err := account.prepFunctionInvokeRPC(ctx, "estimate", calls, details)
if err != nil {
return nil, err
}
switch account.version {
case 1:
estimates, err := account.rpcv02.EstimateFee(ctx, []rpcv02.BroadcastedTransaction{rpcv02.BroadcastedInvokeV1Transaction{
BroadcastedTxnCommonProperties: rpcv02.BroadcastedTxnCommonProperties{
estimates, err := account.rpc.EstimateFee(ctx, []rpc.BroadcastedTransaction{rpc.BroadcastedInvokeV1Transaction{
BroadcastedTxnCommonProperties: rpc.BroadcastedTxnCommonProperties{
MaxFee: call.MaxFee,
Version: rpcv02.TransactionV1,
Version: rpc.TransactionV1,
Signature: call.Signature,
Nonce: call.Nonce,
Type: "INVOKE",
},
Calldata: call.Calldata,
SenderAddress: account.AccountAddress,
}}, rpcv02.WithBlockTag("latest"))
}}, rpc.WithBlockTag("latest"))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -490,17 +490,17 @@ func (account *Account) Execute(ctx context.Context, calls []types.FunctionCall,
details.MaxFee = maxFee

switch account.provider {
case ProviderRPCv02:
call, err := account.prepFunctionInvokeRPCv02(ctx, "invoke", calls, details)
case ProviderRPC:
call, err := account.prepFunctionInvokeRPC(ctx, "invoke", calls, details)
if err != nil {
return nil, err
}
switch account.version {
case 1:
resp, err := account.rpcv02.AddInvokeTransaction(ctx, rpcv02.BroadcastedInvokeV1Transaction{
BroadcastedTxnCommonProperties: rpcv02.BroadcastedTxnCommonProperties{
resp, err := account.rpc.AddInvokeTransaction(ctx, rpc.BroadcastedInvokeV1Transaction{
BroadcastedTxnCommonProperties: rpc.BroadcastedTxnCommonProperties{
MaxFee: call.MaxFee,
Version: rpcv02.TransactionV1,
Version: rpc.TransactionV1,
Signature: call.Signature,
Nonce: call.Nonce,
Type: "INVOKE",
Expand All @@ -526,9 +526,9 @@ func (account *Account) Execute(ctx context.Context, calls []types.FunctionCall,
return nil, ErrUnsupportedAccount
}

func (account *Account) Declare(ctx context.Context, classHash string, contract rpcv02.ContractClass, details types.ExecuteDetails) (types.AddDeclareResponse, error) {
func (account *Account) Declare(ctx context.Context, classHash string, contract rpc.ContractClass, details types.ExecuteDetails) (types.AddDeclareResponse, error) {
switch account.provider {
case ProviderRPCv02:
case ProviderRPC:
panic("unsupported")
case ProviderGateway:
version := big.NewInt(1)
Expand Down
10 changes: 5 additions & 5 deletions accountrpcv02_test.go → accountrpcv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
"time"

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

// TestAccountNonce tests the account Nonce
func TestRPCv02Account_Nonce(t *testing.T) {
func TestRPCAccount_Nonce(t *testing.T) {
testConfig := beforeRPCEach(t)

type testSetType struct {
Expand Down Expand Up @@ -61,7 +61,7 @@ func TestRPCv02Account_Nonce(t *testing.T) {
}

// TestAccountEstimateFee tests the account EstimateFee
func TestRPCv02Account_EstimateFee(t *testing.T) {
func TestRPCAccount_EstimateFee(t *testing.T) {
testConfig := beforeRPCEach(t)

type testSetType struct {
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestRPCv02Account_EstimateFee(t *testing.T) {
}

// TestRPCAccount_Execute tests the account Execute method
func TestRPCv02Account_Execute(t *testing.T) {
func TestRPCAccount_Execute(t *testing.T) {
testConfig := beforeRPCEach(t)

type testSetType struct {
Expand Down Expand Up @@ -157,7 +157,7 @@ func TestRPCv02Account_Execute(t *testing.T) {
fmt.Println("transaction_hash:", execute.TransactionHash)
ctx, cancel := context.WithTimeout(ctx, 600*time.Second)
defer cancel()
status, err := account.rpcv02.WaitForTransaction(ctx, execute.TransactionHash, 8*time.Second)
status, err := account.rpc.WaitForTransaction(ctx, execute.TransactionHash, 8*time.Second)
if err != nil {
t.Fatal("declare should succeed, instead:", err)
}
Expand Down
8 changes: 4 additions & 4 deletions contracts/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestGateway_InstallAccounts(t *testing.T) {
}
}

func TestRPCv02_InstallAccounts(t *testing.T) {
func TestRPC_InstallAccounts(t *testing.T) {
godotenv.Load()
testConfiguration := beforeEach(t)

Expand All @@ -75,7 +75,7 @@ func TestRPCv02_InstallAccounts(t *testing.T) {
}

devnet := []TestCase{}
for _, provider := range []starknetgo.ProviderType{starknetgo.ProviderRPCv02} {
for _, provider := range []starknetgo.ProviderType{starknetgo.ProviderRPC} {
for _, version := range []string{"v1"} {
for _, proxy := range []bool{false, true} {
for _, plugin := range []bool{false, true} {
Expand All @@ -99,10 +99,10 @@ func TestRPCv02_InstallAccounts(t *testing.T) {
var accountManager *AccountManager
var err error
switch test.providerType {
case starknetgo.ProviderRPCv02:
case starknetgo.ProviderRPC:
accountManager, err = InstallAndWaitForAccount(
ctx,
testConfiguration.rpcv02,
testConfiguration.rpc,
privateKey,
test.CompiledContract,
)
Expand Down
8 changes: 4 additions & 4 deletions contracts/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
starknetgo "github.com/NethermindEth/starknet.go"
"github.com/NethermindEth/starknet.go/artifacts"
"github.com/NethermindEth/starknet.go/gateway"
"github.com/NethermindEth/starknet.go/rpcv02"
"github.com/NethermindEth/starknet.go/rpc"
"github.com/NethermindEth/starknet.go/utils"
)

Expand Down Expand Up @@ -58,8 +58,8 @@ const (

func guessProviderType(p interface{}) (Provider, error) {
switch v := p.(type) {
case *rpcv02.Provider:
provider := RPCv02Provider(*v)
case *rpc.Provider:
provider := RPCProvider(*v)
return &provider, nil
case *gateway.GatewayProvider:
provider := GatewayProvider(*v)
Expand All @@ -72,7 +72,7 @@ func guessProviderType(p interface{}) (Provider, error) {
//
// Deprecated: this function should be replaced by InstallAndWaitForAccount
// that will use the DEPLOY_ACCOUNT syscall.
func InstallAndWaitForAccount[V *rpcv02.Provider | *gateway.GatewayProvider](ctx context.Context, provider V, privateKey *big.Int, compiledContracts artifacts.CompiledContract) (*AccountManager, error) {
func InstallAndWaitForAccount[V *rpc.Provider | *gateway.GatewayProvider](ctx context.Context, provider V, privateKey *big.Int, compiledContracts artifacts.CompiledContract) (*AccountManager, error) {
if len(compiledContracts.AccountCompiled) == 0 {
return nil, errors.New("empty account")
}
Expand Down
Loading
Loading