Skip to content

Commit

Permalink
Merge branch 'main' into rpcv05-estimateFee-params
Browse files Browse the repository at this point in the history
  • Loading branch information
cicr99 committed Oct 30, 2023
2 parents 01e18fd + 322e194 commit db8557f
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 39 deletions.
15 changes: 7 additions & 8 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,17 +604,16 @@ func (account *Account) Events(ctx context.Context, input rpc.EventsInput) (*rpc
return account.provider.Events(ctx, input)
}

// Nonce returns the nonce for the specified account and contract address.
// Nonce retrieves the nonce for a given block ID and contract address.
//
// Parameters:
// - ctx: The context.Context object for the function
// - blockID: the rpc.BlockID object for the function
// - contractAddress: the felt.Felt (address of the contract) whose nonce we're seeking
//
// - ctx: is the context.Context for the function call
// - blockID: is the ID of the block
// - contractAddress: is the address of the contract
// Returns:
// - *string: a string pointer
// - error: an error
func (account *Account) Nonce(ctx context.Context, blockID rpc.BlockID, contractAddress *felt.Felt) (*string, error) {
// - *felt.Felt: the contract's nonce at the requested state
// - error: an error if any
func (account *Account) Nonce(ctx context.Context, blockID rpc.BlockID, contractAddress *felt.Felt) (*felt.Felt, error) {
return account.provider.Nonce(ctx, blockID, contractAddress)
}

Expand Down
2 changes: 1 addition & 1 deletion account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ func TestAddDeclareTxn(t *testing.T) {
require.NoError(t, err)

tx := rpc.DeclareTxnV2{
Nonce: utils.TestHexToFelt(t, *nonce),
Nonce: nonce,
MaxFee: utils.TestHexToFelt(t, "0x50c8f3053db"),
Type: rpc.TransactionType_Declare,
Version: rpc.TransactionV2,
Expand Down
5 changes: 2 additions & 3 deletions examples/simpleInvoke/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ func main() {
panic(err.Error())
}

//Getting the nonce from the account, and then converting it into felt
nonce_string, _ := accnt.Nonce(context.Background(), rpc.BlockID{Tag: "latest"}, accnt.AccountAddress)
nonce, err := utils.HexToFelt(*nonce_string)
//Getting the nonce from the account
nonce, err := accnt.Nonce(context.Background(), rpc.BlockID{Tag: "latest"}, accnt.AccountAddress)
if err != nil {
panic(err.Error())
}
Expand Down
17 changes: 3 additions & 14 deletions mocks/mock_account.go

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

10 changes: 9 additions & 1 deletion mocks/mock_rpc_provider.go

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

8 changes: 4 additions & 4 deletions rpc/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ func (provider *Provider) StorageAt(ctx context.Context, contractAddress *felt.F
// - blockID: is the ID of the block
// - contractAddress: is the address of the contract
// Returns:
// - *string: the nonce
// - *felt.Felt: the contract's nonce at the requested state
// - error: an error if any
func (provider *Provider) Nonce(ctx context.Context, blockID BlockID, contractAddress *felt.Felt) (*string, error) {
nonce := ""
func (provider *Provider) Nonce(ctx context.Context, blockID BlockID, contractAddress *felt.Felt) (*felt.Felt, error) {
var nonce *felt.Felt
if err := do(ctx, provider.c, "starknet_getNonce", &nonce, blockID, contractAddress); err != nil {

return nil, tryUnwrapToRPCErr(err, ErrContractNotFound, ErrBlockNotFound)
}
return &nonce, nil
return nonce, nil
}

// EstimateFee estimates the fee for executing a set of requests on the StarkNet blockchain.
Expand Down
15 changes: 10 additions & 5 deletions rpc/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,19 @@ func TestNonce(t *testing.T) {

type testSetType struct {
ContractAddress *felt.Felt
ExpectedNonce *felt.Felt
}
testSet := map[string][]testSetType{
"mock": {
{
ContractAddress: utils.TestHexToFelt(t, "0x0207acc15dc241e7d167e67e30e769719a727d3e0fa47f9e187707289885dfde"),
ExpectedNonce: utils.TestHexToFelt(t, "0x0"),
},
},
"testnet": {
{
ContractAddress: utils.TestHexToFelt(t, "0x0207acc15dc241e7d167e67e30e769719a727d3e0fa47f9e187707289885dfde"),
ExpectedNonce: utils.TestHexToFelt(t, "0x0"),
},
},
"mainnet": {},
Expand All @@ -341,21 +344,23 @@ func TestNonce(t *testing.T) {
for _, test := range testSet {
spy := NewSpy(testConfig.provider.c)
testConfig.provider.c = spy
value, err := testConfig.provider.Nonce(context.Background(), WithBlockTag("latest"), test.ContractAddress)
nonce, err := testConfig.provider.Nonce(context.Background(), WithBlockTag("latest"), test.ContractAddress)
if err != nil {
t.Fatal(err)
}
diff, err := spy.Compare(value, false)
diff, err := spy.Compare(nonce, false)
if err != nil {
t.Fatal("expecting to match", err)
}
if diff != "FullMatch" {
spy.Compare(value, true)
spy.Compare(nonce, true)
t.Fatal("structure expecting to be FullMatch, instead", diff)
}
if *value != "0x0" {
t.Fatalf("expecting value %s, got %s", "0x0", *value)

if nonce == nil {
t.Fatalf("should return a nonce, instead %v", nonce)
}
require.Equal(t, test.ExpectedNonce, nonce)
}
}

Expand Down
7 changes: 5 additions & 2 deletions rpc/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,9 +810,12 @@ func mock_starknet_getNonce(result interface{}, method string, args ...interface
fmt.Printf("args[0] should be *felt.Felt, got %T\n", args[1])
return errWrongArgs
}
output := "0x0"
output, err := utils.HexToFelt("0x0")
if err != nil {
return err
}
outputContent, _ := json.Marshal(output)
json.Unmarshal(outputContent, &r)
json.Unmarshal(outputContent, r)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion rpc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type RpcProvider interface {
EstimateMessageFee(ctx context.Context, msg MsgFromL1, blockID BlockID) (*FeeEstimate, error)
Events(ctx context.Context, input EventsInput) (*EventChunk, error)
GetTransactionStatus(ctx context.Context, transactionHash *felt.Felt) (*TxnStatusResp, error)
Nonce(ctx context.Context, blockID BlockID, contractAddress *felt.Felt) (*string, error)
Nonce(ctx context.Context, blockID BlockID, contractAddress *felt.Felt) (*felt.Felt, error)
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)
Expand Down

0 comments on commit db8557f

Please sign in to comment.