Skip to content

Commit

Permalink
Implement rpc05 specVersion (#416)
Browse files Browse the repository at this point in the history
* Implement rpc05 specVersion
  • Loading branch information
rianhughes committed Oct 12, 2023
1 parent 77df1fc commit 9c36fa6
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ go run main.go
| `starknet_addDeployAccountTransaction` | :heavy_check_mark: |
| `starknet_traceTransaction` | :heavy_check_mark: |
| `starknet_simulateTransaction` | :heavy_check_mark: |
| `starknet_specVersion` | :heavy_check_mark: |
| `starknet_traceBlockTransactions` | :heavy_check_mark: |

### Run Tests
Expand Down
3 changes: 3 additions & 0 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,9 @@ func (account *Account) StorageAt(ctx context.Context, contractAddress *felt.Fel
func (account *Account) StateUpdate(ctx context.Context, blockID rpc.BlockID) (*rpc.StateUpdateOutput, error) {
return account.provider.StateUpdate(ctx, blockID)
}
func (account *Account) SpecVersion(ctx context.Context) (string, error) {
return account.provider.SpecVersion(ctx)
}
func (account *Account) Syncing(ctx context.Context) (*rpc.SyncStatus, error) {
return account.provider.Syncing(ctx)
}
Expand Down
127 changes: 115 additions & 12 deletions mocks/mock_account.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions mocks/mock_rpc_provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rpc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type RpcProvider interface {
SimulateTransactions(ctx context.Context, blockID BlockID, txns []Transaction, simulationFlags []SimulationFlag) ([]SimulatedTransaction, error)
StateUpdate(ctx context.Context, blockID BlockID) (*StateUpdateOutput, error)
StorageAt(ctx context.Context, contractAddress *felt.Felt, key string, blockID BlockID) (string, error)
SpecVersion(ctx context.Context) (string, error)
Syncing(ctx context.Context) (*SyncStatus, error)
TraceBlockTransactions(ctx context.Context, blockHash *felt.Felt) ([]Trace, error)
TransactionByBlockIdAndIndex(ctx context.Context, blockID BlockID, index uint64) (Transaction, error)
Expand Down
12 changes: 12 additions & 0 deletions rpc/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package rpc

import "context"

// SpecVersion returns the version of the Starknet JSON-RPC specification being used
// Parameters: None
// Returns: String of the Starknet JSON-RPC specification
func (provider *Provider) SpecVersion(ctx context.Context) (string, error) {
var result string
err := do(ctx, provider.c, "starknet_specVersion", &result)
return result, err
}
32 changes: 32 additions & 0 deletions rpc/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package rpc

import (
"context"
"testing"

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

// TestSpecVersion tests starknet_specVersion
func TestSpecVersion(t *testing.T) {

testConfig := beforeEach(t)

type testSetType struct {
ExpectedResp string
}
testSet := map[string][]testSetType{
"devnet": {},
"mainnet": {},
"mock": {},
"testnet": {{
ExpectedResp: "0.5.0",
}},
}[testEnv]

for _, test := range testSet {
resp, err := testConfig.provider.SpecVersion(context.Background())
require.NoError(t, err)
require.Equal(t, test.ExpectedResp, resp)
}
}

0 comments on commit 9c36fa6

Please sign in to comment.