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

Update types to cosmwasm 2.0 version #515

Merged
merged 8 commits into from
Feb 1, 2024
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
9 changes: 9 additions & 0 deletions docs/MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
whether the given string is a valid address. This was previously done
internally using separate calls to `CanonicalizeAddress` and `HumanizeAddress`
but can be done more efficiently using a single call.
- The IBC `TransferMsg` now includes an optional `Memo` field.
- `SubMsgResponse` now has an additional `MsgResponses` field, mirroring the
Cosmos SDK
- The types `Events`, `EventAttributes`, `Delegations`, `IBCChannels`,
`Validators`, `MsgResponses` and `Coins` were replaced with a generic
`Array[C]` type. This new type is a wrapper around a `[]C`. One difference to
the old behavior is that the new type will unmarshal to an empty slice when
the JSON value is `null` or `[]`. Previously, both cases resulted in a `nil`
value.

## Renamings

Expand Down
10 changes: 5 additions & 5 deletions ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestIBCHandshake(t *testing.T) {
// instantiate it with this store
store := api.NewLookup(gasMeter1)
goapi := api.NewMockAPI()
balance := types.Coins{}
balance := types.Array[types.Coin]{}
querier := api.DefaultQuerier(api.MOCK_CONTRACT_ADDR, balance)

// instantiate
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestIBCPacketDispatch(t *testing.T) {
// instantiate it with this store
store := api.NewLookup(gasMeter1)
goapi := api.NewMockAPI()
balance := types.Coins{}
balance := types.Array[types.Coin]{}
querier := api.DefaultQuerier(api.MOCK_CONTRACT_ADDR, balance)

// instantiate
Expand Down Expand Up @@ -210,9 +210,9 @@ func TestIBCPacketDispatch(t *testing.T) {
ID: id,
Result: types.SubMsgResult{
Ok: &types.SubMsgResponse{
Events: types.Events{{
Events: types.Array[types.Event]{{
Type: "instantiate",
Attributes: types.EventAttributes{
Attributes: types.Array[types.EventAttribute]{
{
Key: "_contract_address",
Value: REFLECT_ADDR,
Expand Down Expand Up @@ -249,7 +249,7 @@ func TestIBCPacketDispatch(t *testing.T) {
Msgs: []types.CosmosMsg{{
Bank: &types.BankMsg{Send: &types.SendMsg{
ToAddress: "my-friend",
Amount: types.Coins{types.NewCoin(12345678, "uatom")},
Amount: types.Array[types.Coin]{types.NewCoin(12345678, "uatom")},
}},
}},
},
Expand Down
2 changes: 1 addition & 1 deletion internal/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestValidateAddressFailure(t *testing.T) {
// instantiate it with this store
store := NewLookup(gasMeter)
api := NewMockAPI()
querier := DefaultQuerier(MOCK_CONTRACT_ADDR, types.Coins{types.NewCoin(100, "ATOM")})
querier := DefaultQuerier(MOCK_CONTRACT_ADDR, types.Array[types.Coin]{types.NewCoin(100, "ATOM")})
env := MockEnvBin(t)
info := MockInfoBin(t, "creator")

Expand Down
2 changes: 1 addition & 1 deletion internal/api/iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func setupQueueContractWithData(t *testing.T, cache Cache, values ...int) queueD
// instantiate it with this store
store := NewLookup(gasMeter1)
api := NewMockAPI()
querier := DefaultQuerier(MOCK_CONTRACT_ADDR, types.Coins{types.NewCoin(100, "ATOM")})
querier := DefaultQuerier(MOCK_CONTRACT_ADDR, types.Array[types.Coin]{types.NewCoin(100, "ATOM")})
env := MockEnvBin(t)
info := MockInfoBin(t, "creator")
msg := []byte(`{}`)
Expand Down
32 changes: 16 additions & 16 deletions internal/api/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func TestGetMetrics(t *testing.T) {
igasMeter := types.GasMeter(gasMeter)
store := NewLookup(gasMeter)
api := NewMockAPI()
querier := DefaultQuerier(MOCK_CONTRACT_ADDR, types.Coins{types.NewCoin(100, "ATOM")})
querier := DefaultQuerier(MOCK_CONTRACT_ADDR, types.Array[types.Coin]{types.NewCoin(100, "ATOM")})
env := MockEnvBin(t)
info := MockInfoBin(t, "creator")
msg1 := []byte(`{"verifier": "fred", "beneficiary": "bob"}`)
Expand Down Expand Up @@ -397,7 +397,7 @@ func TestInstantiate(t *testing.T) {
// instantiate it with this store
store := NewLookup(gasMeter)
api := NewMockAPI()
querier := DefaultQuerier(MOCK_CONTRACT_ADDR, types.Coins{types.NewCoin(100, "ATOM")})
querier := DefaultQuerier(MOCK_CONTRACT_ADDR, types.Array[types.Coin]{types.NewCoin(100, "ATOM")})
env := MockEnvBin(t)
info := MockInfoBin(t, "creator")
msg := []byte(`{"verifier": "fred", "beneficiary": "bob"}`)
Expand All @@ -424,7 +424,7 @@ func TestExecute(t *testing.T) {
// instantiate it with this store
store := NewLookup(gasMeter1)
api := NewMockAPI()
balance := types.Coins{types.NewCoin(250, "ATOM")}
balance := types.Array[types.Coin]{types.NewCoin(250, "ATOM")}
querier := DefaultQuerier(MOCK_CONTRACT_ADDR, balance)
env := MockEnvBin(t)
info := MockInfoBin(t, "creator")
Expand Down Expand Up @@ -489,7 +489,7 @@ func TestExecutePanic(t *testing.T) {
// instantiate it with this store
store := NewLookup(gasMeter1)
api := NewMockAPI()
balance := types.Coins{types.NewCoin(250, "ATOM")}
balance := types.Array[types.Coin]{types.NewCoin(250, "ATOM")}
querier := DefaultQuerier(MOCK_CONTRACT_ADDR, balance)
env := MockEnvBin(t)
info := MockInfoBin(t, "creator")
Expand Down Expand Up @@ -518,7 +518,7 @@ func TestExecuteUnreachable(t *testing.T) {
// instantiate it with this store
store := NewLookup(gasMeter1)
api := NewMockAPI()
balance := types.Coins{types.NewCoin(250, "ATOM")}
balance := types.Array[types.Coin]{types.NewCoin(250, "ATOM")}
querier := DefaultQuerier(MOCK_CONTRACT_ADDR, balance)
env := MockEnvBin(t)
info := MockInfoBin(t, "creator")
Expand Down Expand Up @@ -702,7 +702,7 @@ func TestExecuteUserErrorsInApiCalls(t *testing.T) {
igasMeter1 := types.GasMeter(gasMeter1)
// instantiate it with this store
store := NewLookup(gasMeter1)
balance := types.Coins{types.NewCoin(250, "ATOM")}
balance := types.Array[types.Coin]{types.NewCoin(250, "ATOM")}
querier := DefaultQuerier(MOCK_CONTRACT_ADDR, balance)
env := MockEnvBin(t)
info := MockInfoBin(t, "creator")
Expand Down Expand Up @@ -733,7 +733,7 @@ func TestMigrate(t *testing.T) {
// instantiate it with this store
store := NewLookup(gasMeter)
api := NewMockAPI()
balance := types.Coins{types.NewCoin(250, "ATOM")}
balance := types.Array[types.Coin]{types.NewCoin(250, "ATOM")}
querier := DefaultQuerier(MOCK_CONTRACT_ADDR, balance)
env := MockEnvBin(t)
info := MockInfoBin(t, "creator")
Expand Down Expand Up @@ -778,7 +778,7 @@ func TestMultipleInstances(t *testing.T) {
igasMeter1 := types.GasMeter(gasMeter1)
store1 := NewLookup(gasMeter1)
api := NewMockAPI()
querier := DefaultQuerier(MOCK_CONTRACT_ADDR, types.Coins{types.NewCoin(100, "ATOM")})
querier := DefaultQuerier(MOCK_CONTRACT_ADDR, types.Array[types.Coin]{types.NewCoin(100, "ATOM")})
env := MockEnvBin(t)
info := MockInfoBin(t, "regen")
msg := []byte(`{"verifier": "fred", "beneficiary": "bob"}`)
Expand Down Expand Up @@ -832,7 +832,7 @@ func TestSudo(t *testing.T) {
// instantiate it with this store
store := NewLookup(gasMeter1)
api := NewMockAPI()
balance := types.Coins{types.NewCoin(250, "ATOM")}
balance := types.Array[types.Coin]{types.NewCoin(250, "ATOM")}
querier := DefaultQuerier(MOCK_CONTRACT_ADDR, balance)
env := MockEnvBin(t)
info := MockInfoBin(t, "creator")
Expand Down Expand Up @@ -862,7 +862,7 @@ func TestSudo(t *testing.T) {
require.NotNil(t, dispatch.Bank.Send, "%#v", dispatch)
send := dispatch.Bank.Send
assert.Equal(t, "community-pool", send.ToAddress)
expectedPayout := types.Coins{types.NewCoin(700, "gold")}
expectedPayout := types.Array[types.Coin]{types.NewCoin(700, "gold")}
assert.Equal(t, expectedPayout, send.Amount)
}

Expand Down Expand Up @@ -891,7 +891,7 @@ func TestDispatchSubmessage(t *testing.T) {
ID: id,
Msg: types.CosmosMsg{Bank: &types.BankMsg{Send: &types.SendMsg{
ToAddress: "friend",
Amount: types.Coins{types.NewCoin(1, "token")},
Amount: types.Array[types.Coin]{types.NewCoin(1, "token")},
}}},
ReplyOn: types.ReplyAlways,
}
Expand Down Expand Up @@ -940,9 +940,9 @@ func TestReplyAndQuery(t *testing.T) {

var id uint64 = 1234
data := []byte("foobar")
events := types.Events{{
events := types.Array[types.Event]{{
Type: "message",
Attributes: types.EventAttributes{{
Attributes: types.Array[types.EventAttribute]{{
Key: "signer",
Value: "caller-addr",
}},
Expand Down Expand Up @@ -1067,7 +1067,7 @@ func TestQuery(t *testing.T) {
igasMeter1 := types.GasMeter(gasMeter1)
store := NewLookup(gasMeter1)
api := NewMockAPI()
querier := DefaultQuerier(MOCK_CONTRACT_ADDR, types.Coins{types.NewCoin(100, "ATOM")})
querier := DefaultQuerier(MOCK_CONTRACT_ADDR, types.Array[types.Coin]{types.NewCoin(100, "ATOM")})
env := MockEnvBin(t)
info := MockInfoBin(t, "creator")
msg := []byte(`{"verifier": "fred", "beneficiary": "bob"}`)
Expand Down Expand Up @@ -1110,7 +1110,7 @@ func TestHackatomQuerier(t *testing.T) {
igasMeter := types.GasMeter(gasMeter)
store := NewLookup(gasMeter)
api := NewMockAPI()
initBalance := types.Coins{types.NewCoin(1234, "ATOM"), types.NewCoin(65432, "ETH")}
initBalance := types.Array[types.Coin]{types.NewCoin(1234, "ATOM"), types.NewCoin(65432, "ETH")}
querier := DefaultQuerier("foobar", initBalance)

// make a valid query to the other address
Expand Down Expand Up @@ -1153,7 +1153,7 @@ func TestCustomReflectQuerier(t *testing.T) {
igasMeter := types.GasMeter(gasMeter)
store := NewLookup(gasMeter)
api := NewMockAPI()
initBalance := types.Coins{types.NewCoin(1234, "ATOM")}
initBalance := types.Array[types.Coin]{types.NewCoin(1234, "ATOM")}
querier := DefaultQuerier(MOCK_CONTRACT_ADDR, initBalance)
// we need this to handle the custom requests from the reflect contract
innerQuerier := querier.(*MockQuerier)
Expand Down
14 changes: 7 additions & 7 deletions internal/api/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,8 @@ type MockQuerier struct {

var _ types.Querier = &MockQuerier{}

func DefaultQuerier(contractAddr string, coins types.Coins) types.Querier {
balances := map[string]types.Coins{
func DefaultQuerier(contractAddr string, coins types.Array[types.Coin]) types.Querier {
balances := map[string]types.Array[types.Coin]{
contractAddr: coins,
}
return &MockQuerier{
Expand Down Expand Up @@ -449,11 +449,11 @@ func (q MockQuerier) GasConsumed() uint64 {
}

type BankQuerier struct {
Balances map[string]types.Coins
Balances map[string]types.Array[types.Coin]
}

func NewBankQuerier(balances map[string]types.Coins) BankQuerier {
bal := make(map[string]types.Coins, len(balances))
func NewBankQuerier(balances map[string]types.Array[types.Coin]) BankQuerier {
bal := make(map[string]types.Array[types.Coin], len(balances))
for k, v := range balances {
dst := make([]types.Coin, len(v))
copy(dst, v)
Expand Down Expand Up @@ -540,7 +540,7 @@ func (q ReflectCustom) Query(request json.RawMessage) ([]byte, error) {

func TestBankQuerierAllBalances(t *testing.T) {
addr := "foobar"
balance := types.Coins{types.NewCoin(12345678, "ATOM"), types.NewCoin(54321, "ETH")}
balance := types.Array[types.Coin]{types.NewCoin(12345678, "ATOM"), types.NewCoin(54321, "ETH")}
q := DefaultQuerier(addr, balance)

// query existing account
Expand Down Expand Up @@ -576,7 +576,7 @@ func TestBankQuerierAllBalances(t *testing.T) {

func TestBankQuerierBalance(t *testing.T) {
addr := "foobar"
balance := types.Coins{types.NewCoin(12345678, "ATOM"), types.NewCoin(54321, "ETH")}
balance := types.Array[types.Coin]{types.NewCoin(12345678, "ATOM"), types.NewCoin(54321, "ETH")}
q := DefaultQuerier(addr, balance)

// query existing account with matching denom
Expand Down
6 changes: 3 additions & 3 deletions lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestHappyPath(t *testing.T) {
// instantiate it with this store
store := api.NewLookup(gasMeter1)
goapi := api.NewMockAPI()
balance := types.Coins{types.NewCoin(250, "ATOM")}
balance := types.Array[types.Coin]{types.NewCoin(250, "ATOM")}
querier := api.DefaultQuerier(api.MOCK_CONTRACT_ADDR, balance)

// instantiate
Expand Down Expand Up @@ -184,7 +184,7 @@ func TestEnv(t *testing.T) {
// instantiate it with this store
store := api.NewLookup(gasMeter1)
goapi := api.NewMockAPI()
balance := types.Coins{types.NewCoin(250, "ATOM")}
balance := types.Array[types.Coin]{types.NewCoin(250, "ATOM")}
querier := api.DefaultQuerier(api.MOCK_CONTRACT_ADDR, balance)

// instantiate
Expand Down Expand Up @@ -264,7 +264,7 @@ func TestGetMetrics(t *testing.T) {
// instantiate it with this store
store := api.NewLookup(gasMeter1)
goapi := api.NewMockAPI()
balance := types.Coins{types.NewCoin(250, "ATOM")}
balance := types.Array[types.Coin]{types.NewCoin(250, "ATOM")}
querier := api.DefaultQuerier(api.MOCK_CONTRACT_ADDR, balance)

env := api.MockEnv()
Expand Down
2 changes: 1 addition & 1 deletion types/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ type MessageInfo struct {
// Bech32 encoded sdk.AccAddress executing the contract
Sender HumanAddress `json:"sender"`
// Amount of funds send to the contract along with this message
Funds Coins `json:"funds"`
Funds Array[Coin] `json:"funds"`
}
6 changes: 5 additions & 1 deletion types/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ func TestMessageInfoHandlesMissingCoins(t *testing.T) {
require.NoError(t, err)

// we can unmarshal it properly into struct
expected := MessageInfo{
Sender: "baz",
Funds: []Coin{},
}
var recover MessageInfo
err = json.Unmarshal(bz, &recover)
require.NoError(t, err)
assert.Equal(t, info, recover)
assert.Equal(t, expected, recover)

// make sure "funds":[] is in JSON
var raw map[string]json.RawMessage
Expand Down
25 changes: 25 additions & 0 deletions types/ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,28 @@ func TestIbcTimeoutDeserialization(t *testing.T) {
Timestamp: 0,
}, timeout4)
}

func TestIbcReceiveResponseDeserialization(t *testing.T) {
var err error

// without acknowledgement
var resp IBCReceiveResponse
err = json.Unmarshal([]byte(`{"acknowledgement":null,"messages":[],"attributes":[],"events":[]}`), &resp)
require.NoError(t, err)
assert.Equal(t, IBCReceiveResponse{
Acknowledgement: nil,
Messages: []SubMsg{},
Attributes: []EventAttribute{},
Events: []Event{},
}, resp)

// with acknowledgement
err = json.Unmarshal([]byte(`{"acknowledgement":"YWNr","messages":[],"attributes":[],"events":[]}`), &resp)
require.NoError(t, err)
assert.Equal(t, IBCReceiveResponse{
Acknowledgement: []byte("ack"),
Messages: []SubMsg{},
Attributes: []EventAttribute{},
Events: []Event{},
}, resp)
}
chipshort marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading