Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 9199306
Author: thiagodeev <[email protected]>
Date:   Mon Jan 6 08:26:54 2025 -0300

    Fixes failing test

commit a6014d4
Merge: 9591073 1bd1947
Author: Thiago Ribeiro <[email protected]>
Date:   Mon Jan 6 08:18:12 2025 -0300

    Merge branch 'main' into v0.8.0

commit 9591073
Author: Thiago Ribeiro <[email protected]>
Date:   Mon Jan 6 07:15:42 2025 -0300

    New rpcdata + RPCv08 errors (#649)

    Update RPC rrror structure to handle RPv0.8.0 errors

commit 1bd1947
Author: Thiago Ribeiro <[email protected]>
Date:   Wed Dec 18 13:00:30 2024 -0300

    Creates a description for the multi-call feature (#648)

    * description of the multi call feature

    * Improves description
  • Loading branch information
thiagodeev committed Jan 13, 2025
1 parent a990cb1 commit f846bb8
Show file tree
Hide file tree
Showing 18 changed files with 208 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_account.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
run: cd account && go test -timeout 600s -v -env devnet .
env:
TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }}
INTEGRATION_BASE: "http://0.0.0.0:5050"
INTEGRATION_BASE: "http://localhost:5050"

# Test Account on mock
- name: Test Account with mocks
Expand Down
2 changes: 1 addition & 1 deletion account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ func (account *Account) WaitForTransactionReceipt(ctx context.Context, transacti
for {
select {
case <-ctx.Done():
return nil, rpc.Err(rpc.InternalError, ctx.Err())
return nil, rpc.Err(rpc.InternalError, &rpc.RPCData{Message: ctx.Err().Error()})
case <-t.C:
receiptWithBlockInfo, err := account.TransactionReceipt(ctx, transactionHash)
if err != nil {
Expand Down
14 changes: 8 additions & 6 deletions account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ func TestWaitForTransactionReceiptMOCK(t *testing.T) {
ShouldCallTransactionReceipt: true,
Hash: new(felt.Felt).SetUint64(1),
ExpectedReceipt: nil,
ExpectedErr: rpc.Err(rpc.InternalError, "UnExpectedErr"),
ExpectedErr: rpc.Err(rpc.InternalError, &rpc.RPCData{Message: "UnExpectedErr"}),
},
{
Timeout: time.Duration(1000),
Expand All @@ -1010,7 +1010,7 @@ func TestWaitForTransactionReceiptMOCK(t *testing.T) {
Hash: new(felt.Felt).SetUint64(3),
ShouldCallTransactionReceipt: false,
ExpectedReceipt: nil,
ExpectedErr: rpc.Err(rpc.InternalError, context.DeadlineExceeded),
ExpectedErr: rpc.Err(rpc.InternalError, &rpc.RPCData{Message: context.DeadlineExceeded.Error()}),
},
},
}[testEnv]
Expand Down Expand Up @@ -1067,7 +1067,7 @@ func TestWaitForTransactionReceipt(t *testing.T) {
type testSetType struct {
Timeout int
Hash *felt.Felt
ExpectedErr error
ExpectedErr *rpc.RPCError
ExpectedReceipt rpc.TransactionReceipt
}
testSet := map[string][]testSetType{
Expand All @@ -1076,7 +1076,7 @@ func TestWaitForTransactionReceipt(t *testing.T) {
Timeout: 3, // Should poll 3 times
Hash: new(felt.Felt).SetUint64(100),
ExpectedReceipt: rpc.TransactionReceipt{},
ExpectedErr: rpc.Err(rpc.InternalError, "Post \"http://0.0.0.0:5050/\": context deadline exceeded"),
ExpectedErr: rpc.Err(rpc.InternalError, &rpc.RPCData{Message: "Post \"http://localhost:5050\": context deadline exceeded"}),
},
},
}[testEnv]
Expand All @@ -1087,11 +1087,13 @@ func TestWaitForTransactionReceipt(t *testing.T) {

resp, err := acnt.WaitForTransactionReceipt(ctx, test.Hash, 1*time.Second)
if test.ExpectedErr != nil {
require.Equal(t, test.ExpectedErr.Error(), err.Error())
rpcErr, ok := err.(*rpc.RPCError)
require.True(t, ok)
require.Equal(t, test.ExpectedErr.Code, rpcErr.Code)
require.Equal(t, test.ExpectedErr.Data.Message, rpcErr.Data.Message)
} else {
require.Equal(t, test.ExpectedReceipt.ExecutionStatus, (*resp).ExecutionStatus)
}

}
}

Expand Down
3 changes: 2 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ To run an example:
R: See [deployContractUDC](./deployContractUDC/main.go).
1. How to send an invoke transaction?
R: See [simpleInvoke](./simpleInvoke/main.go).
1. How to make multiple function calls in the same transaction?
R: See [simpleInvoke](./simpleInvoke/main.go), line 92.
1. How to get the transaction status?
R: See [simpleInvoke](./simpleInvoke/main.go), line 131.
1. How to deploy an ERC20 token?
Expand All @@ -38,4 +40,3 @@ To run an example:
R: See [simpleCall](./simpleCall/main.go).
1. How to sign and verify a typed data?
R: See [typedData](./typedData/main.go).

4 changes: 4 additions & 0 deletions examples/simpleInvoke/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func main() {
}

// Building the Calldata with the help of FmtCalldata where we pass in the FnCall struct along with the Cairo version
//
// note: in Starknet, you can execute multiple function calls in the same transaction, even if they are from different contracts.
// To do this in Starknet.go, just group all the function calls in the same slice and pass it to FmtCalldata
// e.g. : InvokeTx.Calldata, err = accnt.FmtCalldata([]rpc.FunctionCall{funcCall, anotherFuncCall, yetAnotherFuncCallFromDifferentContract})
InvokeTx.Calldata, err = accnt.FmtCalldata([]rpc.FunctionCall{FnCall})
if err != nil {
panic(err)
Expand Down
6 changes: 3 additions & 3 deletions rpc/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,20 @@ func (provider *Provider) BlockWithReceipts(ctx context.Context, blockID BlockID

var m map[string]interface{}
if err := json.Unmarshal(result, &m); err != nil {
return nil, Err(InternalError, err.Error())
return nil, Err(InternalError, &RPCData{Message: err.Error()})
}

// PendingBlockWithReceipts doesn't contain a "status" field
if _, ok := m["status"]; ok {
var block BlockWithReceipts
if err := json.Unmarshal(result, &block); err != nil {
return nil, Err(InternalError, err.Error())
return nil, Err(InternalError, &RPCData{Message: err.Error()})
}
return &block, nil
} else {
var pendingBlock PendingBlockWithReceipts
if err := json.Unmarshal(result, &pendingBlock); err != nil {
return nil, Err(InternalError, err.Error())
return nil, Err(InternalError, &RPCData{Message: err.Error()})
}
return &pendingBlock, nil
}
Expand Down
7 changes: 5 additions & 2 deletions rpc/call_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestCall(t *testing.T) {
FunctionCall FunctionCall
BlockID BlockID
ExpectedPatternResult *felt.Felt
ExpectedError error
ExpectedError *RPCError
}
testSet := map[string][]testSetType{
"devnet": {
Expand Down Expand Up @@ -111,7 +111,10 @@ func TestCall(t *testing.T) {
require := require.New(t)
output, err := testConfig.provider.Call(context.Background(), FunctionCall(test.FunctionCall), test.BlockID)
if test.ExpectedError != nil {
require.EqualError(test.ExpectedError, err.Error())
rpcErr, ok := err.(*RPCError)
require.True(ok)
require.Equal(test.ExpectedError.Code, rpcErr.Code)
require.Equal(test.ExpectedError.Message, rpcErr.Message)
} else {
require.NoError(err)
require.NotEmpty(output, "should return an output")
Expand Down
4 changes: 2 additions & 2 deletions rpc/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ func (provider *Provider) Syncing(ctx context.Context) (*SyncStatus, error) {
var result interface{}
// Note: []interface{}{}...force an empty `params[]` in the jsonrpc request
if err := provider.c.CallContext(ctx, &result, "starknet_syncing", []interface{}{}...); err != nil {
return nil, Err(InternalError, err)
return nil, Err(InternalError, &RPCData{Message: err.Error()})
}
switch res := result.(type) {
case bool:
return &SyncStatus{SyncStatus: &res}, nil
case SyncStatus:
return &res, nil
default:
return nil, Err(InternalError, "internal error with starknet_syncing")
return nil, Err(InternalError, &RPCData{Message: "internal error with starknet_syncing"})
}

}
6 changes: 3 additions & 3 deletions rpc/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@ func (provider *Provider) ClassAt(ctx context.Context, blockID BlockID, contract
func typecastClassOutput(rawClass map[string]any) (ClassOutput, error) {
rawClassByte, err := json.Marshal(rawClass)
if err != nil {
return nil, Err(InternalError, err)
return nil, Err(InternalError, &RPCData{Message: err.Error()})
}

// if contract_class_version exists, then it's a ContractClass type
if _, exists := (rawClass)["contract_class_version"]; exists {
var contractClass ContractClass
err = json.Unmarshal(rawClassByte, &contractClass)
if err != nil {
return nil, Err(InternalError, err)
return nil, Err(InternalError, &RPCData{Message: err.Error()})
}
return &contractClass, nil
}
var depContractClass DeprecatedContractClass
err = json.Unmarshal(rawClassByte, &depContractClass)
if err != nil {
return nil, Err(InternalError, err)
return nil, Err(InternalError, &RPCData{Message: err.Error()})
}
return &depContractClass, nil
}
Expand Down
8 changes: 6 additions & 2 deletions rpc/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ func TestEstimateMessageFee(t *testing.T) {
MsgFromL1
BlockID
ExpectedFeeEst *FeeEstimation
ExpectedError error
ExpectedError *RPCError
}

// https://sepolia.voyager.online/message/0x273f4e20fc522098a60099e5872ab3deeb7fb8321a03dadbd866ac90b7268361
Expand Down Expand Up @@ -470,7 +470,10 @@ func TestEstimateMessageFee(t *testing.T) {
for _, test := range testSet {
resp, err := testConfig.provider.EstimateMessageFee(context.Background(), test.MsgFromL1, test.BlockID)
if err != nil {
require.EqualError(t, test.ExpectedError, err.Error())
rpcErr, ok := err.(*RPCError)
require.True(t, ok)
require.Equal(t, test.ExpectedError.Code, rpcErr.Code)
require.Equal(t, test.ExpectedError.Message, rpcErr.Message)
} else {
require.Exactly(t, test.ExpectedFeeEst, resp)
}
Expand All @@ -479,6 +482,7 @@ func TestEstimateMessageFee(t *testing.T) {

func TestEstimateFee(t *testing.T) {
//TODO: upgrade the mainnet and testnet test cases before merge
t.Skip("TODO: create a test case for the new 'CONTRACT_EXECUTION_ERROR' type")

testConfig := beforeEach(t)

Expand Down
Loading

0 comments on commit f846bb8

Please sign in to comment.