Skip to content

Commit

Permalink
update version and write tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AryanGodara committed May 28, 2024
1 parent 81ad4d3 commit 5af1a68
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
6 changes: 4 additions & 2 deletions rpc/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package rpc

import "context"
import (
"context"
)

// SpecVersion returns the version of the Starknet JSON-RPC specification being used
// Parameters: None
Expand All @@ -9,7 +11,7 @@ func (provider *Provider) SpecVersion(ctx context.Context) (string, error) {
var result string
err := do(ctx, provider.c, "starknet_specVersion", &result)
if err != nil {
return "", Err(InternalError, err)
return "", Err(InternalError, err.Error())
}
return result, nil
}
4 changes: 2 additions & 2 deletions rpc/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestSpecVersion(t *testing.T) {

for _, test := range testSet {
resp, err := testConfig.provider.SpecVersion(context.Background())
require.NoError(t, err)
require.Equal(t, test.ExpectedResp, resp)
require.Nil(t, err)
require.Equal(t, test.ExpectedResp, resp, "Expected spec version mismatch")
}
}
22 changes: 14 additions & 8 deletions rpc/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestDeclareTransaction(t *testing.T) {
{
DeclareTx: DeclareTxnV2{},
ExpectedResp: AddDeclareTransactionResponse{
TransactionHash: utils.TestHexToFelt(t, "0x41d1f5206ef58a443e7d3d1ca073171ec25fa75313394318fc83a074a6631c3")},
TransactionHash: utils.TestHexToFelt(t, "0x2ae47304b5c66be71234bf6c1ed7ddcc9e0eef148f335b50f22167ae817a68")},
ExpectedError: nil,
},
{
Expand Down Expand Up @@ -57,22 +57,28 @@ func TestDeclareTransaction(t *testing.T) {
AccountDeploymentData: []*felt.Felt{},
},
ExpectedResp: AddDeclareTransactionResponse{
TransactionHash: utils.TestHexToFelt(t, "0x41d1f5206ef58a443e7d3d1ca073171ec25fa75313394318fc83a074a6631c3")},
TransactionHash: utils.TestHexToFelt(t, "0x2ae47304b5c66be71234bf6c1ed7ddcc9e0eef148f335b50f22167ae817a68")},
ExpectedError: nil,
},
},
"testnet": {{
DeclareTx: DeclareTxnV1{},
DeclareTx: DeclareTxnV2{},
ExpectedResp: AddDeclareTransactionResponse{
TransactionHash: utils.TestHexToFelt(t, "0x55b094dc5c84c2042e067824f82da90988674314d37e45cb0032aca33d6e0b9")},
ExpectedError: errors.New("Invalid Params"),
TransactionHash: utils.TestHexToFelt(t, "0x2ae47304b5c66be71234bf6c1ed7ddcc9e0eef148f335b50f22167ae817a68")},
ExpectedError: errors.New("Internal Error: Invalid params"),
},
{
DeclareTx: DeclareTxnV2{},
ExpectedResp: AddDeclareTransactionResponse{
TransactionHash: utils.TestHexToFelt(t, "0x3378654b74a56768cfaac97e211103d8233b829bbe663288f292499c03baa2c")},
ExpectedError: errors.New("Internal Error: Invalid params"),
},
},
}[testEnv]

for _, test := range testSet {
if test.DeclareTx == nil && testEnv == "testnet" {
declareTxJSON, err := os.ReadFile("./tests/write/declareTx.json")
declareTxJSON, err := os.ReadFile("./tests/write/git.json")
if err != nil {
t.Fatal("should be able to read file", err)
}
Expand All @@ -83,9 +89,9 @@ func TestDeclareTransaction(t *testing.T) {

resp, err := testConfig.provider.AddDeclareTransaction(context.Background(), test.DeclareTx)
if err != nil {
require.Equal(t, err.Error(), test.ExpectedError)
require.Contains(t, test.ExpectedError.Error(), err.Error())
} else {
require.Equal(t, (*resp.TransactionHash).String(), (*test.ExpectedResp.TransactionHash).String())
require.Equal(t, (*test.ExpectedResp.TransactionHash).String(), (*resp.TransactionHash).String())
}

}
Expand Down

0 comments on commit 5af1a68

Please sign in to comment.