Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: Sync client object with latest spec. #613

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions client/v2/common/models/application_initial_states.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package models

// ApplicationInitialStates an application's initial global/local/box states that
// were accessed during simulation.
type ApplicationInitialStates struct {
// AppBoxes an application's global/local/box state.
AppBoxes ApplicationKVStorage `json:"app-boxes,omitempty"`

// AppGlobals an application's global/local/box state.
AppGlobals ApplicationKVStorage `json:"app-globals,omitempty"`

// AppLocals an application's initial local states tied to different accounts.
AppLocals []ApplicationKVStorage `json:"app-locals,omitempty"`

// Id application index.
Id uint64 `json:"id"`
}
10 changes: 10 additions & 0 deletions client/v2/common/models/application_k_v_storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package models

// ApplicationKVStorage an application's global/local/box state.
type ApplicationKVStorage struct {
// Account the address of the account associated with the local state.
Account string `json:"account,omitempty"`

// Kvs key-Value pairs representing application states.
Kvs []AvmKeyValue `json:"kvs"`
}
22 changes: 22 additions & 0 deletions client/v2/common/models/application_state_operation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package models

// ApplicationStateOperation an operation against an application's global/local/box
// state.
type ApplicationStateOperation struct {
// Account for local state changes, the address of the account associated with the
// local state.
Account string `json:"account,omitempty"`

// AppStateType type of application state. Value `g` is **global state**, `l` is
// **local state**, `b` is **boxes**.
AppStateType string `json:"app-state-type"`

// Key the key (name) of the global/local/box state.
Key []byte `json:"key"`

// NewValue represents an AVM value.
NewValue AvmValue `json:"new-value,omitempty"`

// Operation operation type. Value `w` is **write**, `d` is **delete**.
Operation string `json:"operation"`
}
10 changes: 10 additions & 0 deletions client/v2/common/models/avm_key_value.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package models

// AvmKeyValue represents an AVM key-value pair in an application store.
type AvmKeyValue struct {
// Key
Key []byte `json:"key"`

// Value represents an AVM value.
Value AvmValue `json:"value"`
}
9 changes: 9 additions & 0 deletions client/v2/common/models/simulate_initial_states.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package models

// SimulateInitialStates initial states of resources that were accessed during
// simulation.
type SimulateInitialStates struct {
// AppInitialStates the initial states of accessed application before simulation.
// The order of this array is arbitrary.
AppInitialStates []ApplicationInitialStates `json:"app-initial-states,omitempty"`
}
6 changes: 6 additions & 0 deletions client/v2/common/models/simulate_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ type SimulateRequest struct {
// transaction group.
ExtraOpcodeBudget uint64 `json:"extra-opcode-budget,omitempty"`

// Round if provided, specifies the round preceding the simulation. State changes
// through this round will be used to run this simulation. Usually only the 4 most
// recent rounds will be available (controlled by the node config value
// MaxAcctLookback). If not specified, defaults to the latest available round.
Round uint64 `json:"round,omitempty"`

// TxnGroups the transaction groups to simulate.
TxnGroups []SimulateRequestTransactionGroup `json:"txn-groups"`
}
3 changes: 3 additions & 0 deletions client/v2/common/models/simulate_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ type SimulateResponse struct {
// ExecTraceConfig an object that configures simulation execution trace.
ExecTraceConfig SimulateTraceConfig `json:"exec-trace-config,omitempty"`

// InitialStates initial states of resources that were accessed during simulation.
InitialStates SimulateInitialStates `json:"initial-states,omitempty"`

// LastRound the round immediately preceding this simulation. State changes through
// this round were used to run this simulation.
LastRound uint64 `json:"last-round"`
Expand Down
4 changes: 4 additions & 0 deletions client/v2/common/models/simulate_trace_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ type SimulateTraceConfig struct {
// StackChange a boolean option enabling returning stack changes together with
// execution trace during simulation.
StackChange bool `json:"stack-change,omitempty"`

// StateChange a boolean option enabling returning application state changes
// (global, local, and box changes) with the execution trace during simulation.
StateChange bool `json:"state-change,omitempty"`
}
3 changes: 3 additions & 0 deletions client/v2/common/models/simulation_opcode_trace_unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ type SimulationOpcodeTraceUnit struct {

// StackPopCount the number of deleted stack values by this opcode.
StackPopCount uint64 `json:"stack-pop-count,omitempty"`

// StateChanges the operations against the current application's states.
StateChanges []ApplicationStateOperation `json:"state-changes,omitempty"`
}
11 changes: 11 additions & 0 deletions client/v2/common/models/simulation_transaction_exec_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ package models
// SimulationTransactionExecTrace the execution trace of calling an app or a logic
// sig, containing the inner app call trace in a recursive way.
type SimulationTransactionExecTrace struct {
// ApprovalProgramHash sHA512_256 hash digest of the approval program executed in
// transaction.
ApprovalProgramHash []byte `json:"approval-program-hash,omitempty"`

// ApprovalProgramTrace program trace that contains a trace of opcode effects in an
// approval program.
ApprovalProgramTrace []SimulationOpcodeTraceUnit `json:"approval-program-trace,omitempty"`

// ClearStateProgramHash sHA512_256 hash digest of the clear state program executed
// in transaction.
ClearStateProgramHash []byte `json:"clear-state-program-hash,omitempty"`

// ClearStateProgramTrace program trace that contains a trace of opcode effects in
// a clear state program.
ClearStateProgramTrace []SimulationOpcodeTraceUnit `json:"clear-state-program-trace,omitempty"`
Expand All @@ -15,6 +23,9 @@ type SimulationTransactionExecTrace struct {
// trace of any inner transactions executed.
InnerTrace []SimulationTransactionExecTrace `json:"inner-trace,omitempty"`

// LogicSigHash sHA512_256 hash digest of the logic sig executed in transaction.
LogicSigHash []byte `json:"logic-sig-hash,omitempty"`

// LogicSigTrace program trace that contains a trace of opcode effects in a logic
// sig.
LogicSigTrace []SimulationOpcodeTraceUnit `json:"logic-sig-trace,omitempty"`
Expand Down
10 changes: 10 additions & 0 deletions test/algodclientv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func AlgodClientV2Context(s *godog.Suite) {
s.Step(`^we make a GetLedgerStateDelta call against round (\d+)$`, weMakeAGetLedgerStateDeltaCallAgainstRound)
s.Step(`^we make a LedgerStateDeltaForTransactionGroupResponse call for ID "([^"]*)"$`, weMakeALedgerStateDeltaForTransactionGroupResponseCallForID)
s.Step(`^we make a TransactionGroupLedgerStateDeltaForRoundResponse call for round (\d+)$`, weMakeATransactionGroupLedgerStateDeltaForRoundResponseCallForRound)
s.Step(`^we make a GetBlockTxids call against block number (\d+)$`, weMakeAGetBlockTxidsCallAgainstBlockNumber)

s.BeforeScenario(func(interface{}) {
globalErrForExamination = nil
Expand Down Expand Up @@ -394,3 +395,12 @@ func weMakeATransactionGroupLedgerStateDeltaForRoundResponseCallForRound(round i
algodClient.GetTransactionGroupLedgerStateDeltasForRound(uint64(round)).Do(context.Background())
return nil
}

func weMakeAGetBlockTxidsCallAgainstBlockNumber(round int) error {
algodClient, err := algod.MakeClient(mockServer.URL, "")
if err != nil {
return err
}
algodClient.GetBlockTxids(uint64(round)).Do(context.Background())
return nil
}
3 changes: 3 additions & 0 deletions test/responses_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ func weMakeAnyCallTo(client /* algod/indexer */, endpoint string) (err error) {
case "GetLedgerStateDeltaForTransactionGroup":
response, err =
algodC.GetLedgerStateDeltaForTransactionGroup("someID").Do(context.Background())
case "GetBlockTxids":
response, err =
algodC.GetBlockTxids(123).Do(context.Background())
case "any":
// This is an error case
// pickup the error as the response
Expand Down
2 changes: 2 additions & 0 deletions test/unit.tags
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@unit.applications.boxes
@unit.atomic_transaction_composer
@unit.blocksummary
@unit.blocktxids
@unit.dryrun
@unit.dryrun.trace.application
@unit.feetest
Expand All @@ -26,6 +27,7 @@
@unit.responses.participationupdates
@unit.responses.sync
@unit.responses.timestamp
@unit.responses.txid.json
@unit.responses.unlimited_assets
@unit.sourcemap
@unit.statedelta
Expand Down
Loading