-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* bump cosmwasm to v0.15.0 * emit both from_contract and wasm events to support latest & legacy style, but block from_contract to be passed to a contract * add deprecated comment to from_contract * invalid replyOn check * allow to overwrite response data with reply data * charge gas for wasm events * simplify gov msg parser * use [email protected] * update wasm event spec * fix test for wasm gov * update migration test code to use refect.DeepEqual() * fix migration test to use json.Marshal for correct comparision * register UpgradeHandler for v0.5.0 * fix bank encoding * transfer all luna token to contract for proper simulation * change require.Equal to assert.JSONEq clear migration test
- Loading branch information
yys
authored
Jul 8, 2021
1 parent
d4a3202
commit 3cccea0
Showing
47 changed files
with
755 additions
and
773 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package wasm | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/gov/types" | ||
|
||
wasmvmtypes "github.com/CosmWasm/wasmvm/types" | ||
|
||
wasm "github.com/terra-money/core/x/wasm/exported" | ||
) | ||
|
||
var _ wasm.WasmMsgParserInterface = WasmMsgParser{} | ||
|
||
// WasmMsgParser - wasm msg parser for staking msgs | ||
type WasmMsgParser struct{} | ||
|
||
// NewWasmMsgParser returns bank wasm msg parser | ||
func NewWasmMsgParser() WasmMsgParser { | ||
return WasmMsgParser{} | ||
} | ||
|
||
// Parse implements wasm staking msg parser | ||
func (WasmMsgParser) Parse(contractAddr sdk.AccAddress, wasmMsg wasmvmtypes.CosmosMsg) (sdk.Msg, error) { | ||
msg := wasmMsg.Gov | ||
|
||
var option types.VoteOption | ||
switch msg.Vote.Vote { | ||
case wasmvmtypes.Yes: | ||
option = types.OptionYes | ||
case wasmvmtypes.No: | ||
option = types.OptionNo | ||
case wasmvmtypes.NoWithVeto: | ||
option = types.OptionNoWithVeto | ||
case wasmvmtypes.Abstain: | ||
option = types.OptionAbstain | ||
} | ||
|
||
cosmosMsg := &types.MsgVote{ | ||
ProposalId: msg.Vote.ProposalId, | ||
Voter: contractAddr.String(), | ||
Option: option, | ||
} | ||
|
||
return cosmosMsg, cosmosMsg.ValidateBasic() | ||
} | ||
|
||
// ParseCustom implements custom parser | ||
func (WasmMsgParser) ParseCustom(_ sdk.AccAddress, _ json.RawMessage) (sdk.Msg, error) { | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package wasm | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/tendermint/tendermint/crypto/secp256k1" | ||
|
||
wasmvmtypes "github.com/CosmWasm/wasmvm/types" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
) | ||
|
||
func TestEncoding(t *testing.T) { | ||
addrs := []sdk.AccAddress{ | ||
sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()), | ||
sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()), | ||
sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()), | ||
} | ||
|
||
cases := map[string]struct { | ||
sender sdk.AccAddress | ||
input wasmvmtypes.CosmosMsg | ||
// set if valid | ||
output sdk.Msg | ||
// set if invalid | ||
isError bool | ||
}{ | ||
"yes vote": { | ||
sender: addrs[0], | ||
input: wasmvmtypes.CosmosMsg{ | ||
Gov: &wasmvmtypes.GovMsg{ | ||
Vote: &wasmvmtypes.VoteMsg{ | ||
ProposalId: 1, | ||
Vote: wasmvmtypes.Yes, | ||
}, | ||
}, | ||
}, | ||
output: &govtypes.MsgVote{ | ||
Voter: addrs[0].String(), | ||
ProposalId: 1, | ||
Option: govtypes.OptionYes, | ||
}, | ||
}, | ||
"no vote": { | ||
sender: addrs[0], | ||
input: wasmvmtypes.CosmosMsg{ | ||
Gov: &wasmvmtypes.GovMsg{ | ||
Vote: &wasmvmtypes.VoteMsg{ | ||
ProposalId: 1, | ||
Vote: wasmvmtypes.No, | ||
}, | ||
}, | ||
}, | ||
output: &govtypes.MsgVote{ | ||
Voter: addrs[0].String(), | ||
ProposalId: 1, | ||
Option: govtypes.OptionNo, | ||
}, | ||
}, | ||
"no_with_veto vote": { | ||
sender: addrs[0], | ||
input: wasmvmtypes.CosmosMsg{ | ||
Gov: &wasmvmtypes.GovMsg{ | ||
Vote: &wasmvmtypes.VoteMsg{ | ||
ProposalId: 1, | ||
Vote: wasmvmtypes.NoWithVeto, | ||
}, | ||
}, | ||
}, | ||
output: &govtypes.MsgVote{ | ||
Voter: addrs[0].String(), | ||
ProposalId: 1, | ||
Option: govtypes.OptionNoWithVeto, | ||
}, | ||
}, | ||
"abstain vote": { | ||
sender: addrs[0], | ||
input: wasmvmtypes.CosmosMsg{ | ||
Gov: &wasmvmtypes.GovMsg{ | ||
Vote: &wasmvmtypes.VoteMsg{ | ||
ProposalId: 1, | ||
Vote: wasmvmtypes.Abstain, | ||
}, | ||
}, | ||
}, | ||
output: &govtypes.MsgVote{ | ||
Voter: addrs[0].String(), | ||
ProposalId: 1, | ||
Option: govtypes.OptionAbstain, | ||
}, | ||
}, | ||
} | ||
|
||
parser := NewWasmMsgParser() | ||
for name, tc := range cases { | ||
tc := tc | ||
t.Run(name, func(t *testing.T) { | ||
res, err := parser.Parse(tc.sender, tc.input) | ||
if tc.isError { | ||
require.Error(t, err) | ||
} else { | ||
require.NoError(t, err) | ||
assert.Equal(t, tc.output, res) | ||
} | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.