Skip to content

Commit

Permalink
add UnitConsumed to simulateTransaction RPC method
Browse files Browse the repository at this point in the history
  • Loading branch information
yihau committed Apr 13, 2024
1 parent e9fcffc commit 08bc9af
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
18 changes: 10 additions & 8 deletions client/rpc_simulate_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
)

type SimulateTransaction struct {
Err any
Logs []string
Accounts []*AccountInfo
ReturnData *ReturnData
Err any
Logs []string
Accounts []*AccountInfo
ReturnData *ReturnData
UnitConsumed *uint64
}

type SimulateTransactionConfig struct {
Expand Down Expand Up @@ -135,10 +136,11 @@ func convertSimulateTransaction(v rpc.ValueWithContext[rpc.SimulateTransactionVa
}

return SimulateTransaction{
Err: v.Value.Err,
Logs: v.Value.Logs,
Accounts: accountInfos,
ReturnData: returnData,
Err: v.Value.Err,
Logs: v.Value.Logs,
Accounts: accountInfos,
ReturnData: returnData,
UnitConsumed: v.Value.UnitConsumed,
}, nil
}

Expand Down
3 changes: 3 additions & 0 deletions client/rpc_simulate_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/blocto/solana-go-sdk/common"
"github.com/blocto/solana-go-sdk/internal/client_test"
"github.com/blocto/solana-go-sdk/pkg/pointer"
"github.com/blocto/solana-go-sdk/rpc"
)

Expand Down Expand Up @@ -36,6 +37,7 @@ func TestClient_SimulateTransaction(t *testing.T) {
ProgramId: common.PublicKeyFromString("35HSbe2xiLfid5QJeETGnUsGhkAiJWRKPrEGdQQ5xXrP"),
Data: []byte{1, 2, 3, 4, 5},
},
UnitConsumed: pointer.Get[uint64](185),
},
ExpectedError: nil,
},
Expand Down Expand Up @@ -75,6 +77,7 @@ func TestClient_SimulateTransactionAndContext(t *testing.T) {
ProgramId: common.PublicKeyFromString("35HSbe2xiLfid5QJeETGnUsGhkAiJWRKPrEGdQQ5xXrP"),
Data: []byte{1, 2, 3, 4, 5},
},
UnitConsumed: pointer.Get[uint64](185),
},
},
ExpectedError: nil,
Expand Down
9 changes: 5 additions & 4 deletions rpc/simulate_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ type SimulateTransaction ValueWithContext[SimulateTransactionValue]

// SimulateTransactionValue is a part of SimulateTransactionResponseResult
type SimulateTransactionValue struct {
Err any `json:"err"`
Logs []string `json:"logs,omitempty"`
Accounts []*AccountInfo `json:"accounts,omitempty"`
ReturnData *ReturnData `json:"returnData,omitempty"`
Err any `json:"err"`
Logs []string `json:"logs,omitempty"`
Accounts []*AccountInfo `json:"accounts,omitempty"`
ReturnData *ReturnData `json:"returnData,omitempty"`
UnitConsumed *uint64 `json:"unitsConsumed,omitempty"`
}

type SimulateTransactionConfig struct {
Expand Down
2 changes: 2 additions & 0 deletions rpc/simulate_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/blocto/solana-go-sdk/internal/client_test"
"github.com/blocto/solana-go-sdk/pkg/pointer"
)

func TestSimulateTransaction(t *testing.T) {
Expand Down Expand Up @@ -207,6 +208,7 @@ func TestSimulateTransaction(t *testing.T) {
ProgramId: "35HSbe2xiLfid5QJeETGnUsGhkAiJWRKPrEGdQQ5xXrP",
Data: []any{"AQIDBAU=", "base64"},
},
UnitConsumed: pointer.Get[uint64](185),
},
},
},
Expand Down

0 comments on commit 08bc9af

Please sign in to comment.