Skip to content

Commit

Permalink
Rename entry points to match vm names. (#4986)
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim authored Oct 30, 2023
1 parent 433f1fa commit ddb514d
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions modules/light-clients/08-wasm/types/client_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (cs ClientState) Initialize(ctx sdk.Context, cdc codec.BinaryCodec, clientS
ConsensusState: consensusState,
}

return wasmInit(ctx, clientStore, &cs, payload)
return wasmInstantiate(ctx, clientStore, &cs, payload)
}

// VerifyMembership is a generic proof verification method which verifies a proof of the existence of a value at a given CommitmentPath at the specified height.
Expand Down Expand Up @@ -169,7 +169,7 @@ func (cs ClientState) VerifyMembership(
Value: value,
},
}
_, err := wasmCall[EmptyResult](ctx, clientStore, &cs, payload)
_, err := wasmSudo[EmptyResult](ctx, clientStore, &cs, payload)
return err
}

Expand Down Expand Up @@ -212,6 +212,6 @@ func (cs ClientState) VerifyNonMembership(
Path: merklePath,
},
}
_, err := wasmCall[EmptyResult](ctx, clientStore, &cs, payload)
_, err := wasmSudo[EmptyResult](ctx, clientStore, &cs, payload)
return err
}
12 changes: 6 additions & 6 deletions modules/light-clients/08-wasm/types/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ func WasmQuery[T ContractResult](ctx sdk.Context, clientStore storetypes.KVStore
return wasmQuery[T](ctx, clientStore, cs, payload)
}

// WasmCall wraps wasmCall and is used solely for testing.
func WasmCall[T ContractResult](ctx sdk.Context, clientStore storetypes.KVStore, cs *ClientState, payload SudoMsg) (T, error) {
return wasmCall[T](ctx, clientStore, cs, payload)
// WasmSudo wraps wasmCall and is used solely for testing.
func WasmSudo[T ContractResult](ctx sdk.Context, clientStore storetypes.KVStore, cs *ClientState, payload SudoMsg) (T, error) {
return wasmSudo[T](ctx, clientStore, cs, payload)
}

// WasmInit wraps wasmInit and is used solely for testing.
func WasmInit(ctx sdk.Context, clientStore storetypes.KVStore, cs *ClientState, payload InstantiateMessage) error {
return wasmInit(ctx, clientStore, cs, payload)
// WasmInstantiate wraps wasmInit and is used solely for testing.
func WasmInstantiate(ctx sdk.Context, clientStore storetypes.KVStore, cs *ClientState, payload InstantiateMessage) error {
return wasmInstantiate(ctx, clientStore, cs, payload)
}
2 changes: 1 addition & 1 deletion modules/light-clients/08-wasm/types/proposal_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ func (cs ClientState) CheckSubstituteAndUpdateState(
CheckSubstituteAndUpdateState: &CheckSubstituteAndUpdateStateMsg{},
}

_, err := wasmCall[EmptyResult](ctx, store, &cs, payload)
_, err := wasmSudo[EmptyResult](ctx, store, &cs, payload)
return err
}
4 changes: 2 additions & 2 deletions modules/light-clients/08-wasm/types/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, client
UpdateState: &UpdateStateMsg{ClientMessage: clientMessage},
}

result, err := wasmCall[UpdateStateResult](ctx, clientStore, &cs, payload)
result, err := wasmSudo[UpdateStateResult](ctx, clientStore, &cs, payload)
if err != nil {
panic(err)
}
Expand All @@ -68,7 +68,7 @@ func (cs ClientState) UpdateStateOnMisbehaviour(ctx sdk.Context, _ codec.BinaryC
UpdateStateOnMisbehaviour: &UpdateStateOnMisbehaviourMsg{ClientMessage: clientMessage},
}

_, err := wasmCall[EmptyResult](ctx, clientStore, &cs, payload)
_, err := wasmSudo[EmptyResult](ctx, clientStore, &cs, payload)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion modules/light-clients/08-wasm/types/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ func (cs ClientState) VerifyUpgradeAndUpdateState(
},
}

_, err := wasmCall[EmptyResult](ctx, clientStore, &cs, payload)
_, err := wasmSudo[EmptyResult](ctx, clientStore, &cs, payload)
return err
}
10 changes: 5 additions & 5 deletions modules/light-clients/08-wasm/types/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func queryContract(ctx sdk.Context, clientStore storetypes.KVStore, codeHash []b
return resp, err
}

// wasmInit accepts a message to instantiate a wasm contract, JSON encodes it and calls initContract.
func wasmInit(ctx sdk.Context, clientStore storetypes.KVStore, cs *ClientState, payload InstantiateMessage) error {
// wasmInstantiate accepts a message to instantiate a wasm contract, JSON encodes it and calls initContract.
func wasmInstantiate(ctx sdk.Context, clientStore storetypes.KVStore, cs *ClientState, payload InstantiateMessage) error {
encodedData, err := json.Marshal(payload)
if err != nil {
return errorsmod.Wrap(err, "failed to marshal payload for wasm contract instantiation")
Expand All @@ -90,15 +90,15 @@ func wasmInit(ctx sdk.Context, clientStore storetypes.KVStore, cs *ClientState,
return nil
}

// wasmCall calls the contract with the given payload and returns the result.
// wasmCall returns an error if:
// wasmSudo calls the contract with the given payload and returns the result.
// wasmSudo returns an error if:
// - the payload cannot be marshaled to JSON
// - the contract call returns an error
// - the response of the contract call contains non-empty messages
// - the response of the contract call contains non-empty events
// - the response of the contract call contains non-empty attributes
// - the data bytes of the response cannot be unmarshaled into the result type
func wasmCall[T ContractResult](ctx sdk.Context, clientStore storetypes.KVStore, cs *ClientState, payload SudoMsg) (T, error) {
func wasmSudo[T ContractResult](ctx sdk.Context, clientStore storetypes.KVStore, cs *ClientState, payload SudoMsg) (T, error) {
var result T

encodedData, err := json.Marshal(payload)
Expand Down
4 changes: 2 additions & 2 deletions modules/light-clients/08-wasm/types/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (suite *TypesTestSuite) TestWasmInit() {

tc.malleate()

err := types.WasmInit(suite.ctx, suite.store, &types.ClientState{}, types.InstantiateMessage{})
err := types.WasmInstantiate(suite.ctx, suite.store, &types.ClientState{}, types.InstantiateMessage{})

expPass := tc.expError == nil
if expPass {
Expand Down Expand Up @@ -219,7 +219,7 @@ func (suite *TypesTestSuite) TestWasmCall() {

tc.malleate()

res, err := types.WasmCall[types.UpdateStateResult](suite.ctx, suite.store, wasmClientState, payload)
res, err := types.WasmSudo[types.UpdateStateResult](suite.ctx, suite.store, wasmClientState, payload)

expPass := tc.expError == nil
if expPass {
Expand Down

0 comments on commit ddb514d

Please sign in to comment.