Skip to content

Commit

Permalink
Use Array[Coin] instead of Coins
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Feb 1, 2024
1 parent b51efa2 commit 4bef84b
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 74 deletions.
6 changes: 3 additions & 3 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 @@ -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
28 changes: 14 additions & 14 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 @@ -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"`
}
14 changes: 7 additions & 7 deletions types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ type BankMsg struct {
// SendMsg contains instructions for a Cosmos-SDK/SendMsg
// It has a fixed interface here and should be converted into the proper SDK format before dispatching
type SendMsg struct {
ToAddress string `json:"to_address"`
Amount Coins `json:"amount"`
ToAddress string `json:"to_address"`
Amount Array[Coin] `json:"amount"`
}

// BurnMsg will burn the given coins from the contract's account.
// There is no Cosmos SDK message that performs this, but it can be done by calling the bank keeper.
// Important if a contract controls significant token supply that must be retired.
type BurnMsg struct {
Amount Coins `json:"amount"`
Amount Array[Coin] `json:"amount"`
}

type IBCMsg struct {
Expand Down Expand Up @@ -284,7 +284,7 @@ type WithdrawDelegatorRewardMsg struct {
// `depositor` is automatically filled with the current contract's address
type FundCommunityPoolMsg struct {
// Amount is the list of coins to be send to the community pool
Amount Coins `json:"amount"`
Amount Array[Coin] `json:"amount"`
}

// AnyMsg is encoded the same way as a protobof [Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto).
Expand Down Expand Up @@ -318,7 +318,7 @@ type ExecuteMsg struct {
// as `userMsg` when calling `Handle` on the above-defined contract
Msg []byte `json:"msg"`
// Send is an optional amount of coins this contract sends to the called contract
Funds Coins `json:"funds"`
Funds Array[Coin] `json:"funds"`
}

// InstantiateMsg will create a new contract instance from a previously uploaded CodeID.
Expand All @@ -330,7 +330,7 @@ type InstantiateMsg struct {
// as `userMsg` when calling `Instantiate` on a new contract with the above-defined CodeID
Msg []byte `json:"msg"`
// Send is an optional amount of coins this contract sends to the called contract
Funds Coins `json:"funds"`
Funds Array[Coin] `json:"funds"`
// Label is optional metadata to be stored with a contract instance.
Label string `json:"label"`
// Admin (optional) may be set here to allow future migrations from this address
Expand All @@ -346,7 +346,7 @@ type Instantiate2Msg struct {
// as `userMsg` when calling `Instantiate` on a new contract with the above-defined CodeID
Msg []byte `json:"msg"`
// Send is an optional amount of coins this contract sends to the called contract
Funds Coins `json:"funds"`
Funds Array[Coin] `json:"funds"`
// Label is optional metadata to be stored with a contract instance.
Label string `json:"label"`
// Admin (optional) may be set here to allow future migrations from this address
Expand Down
8 changes: 4 additions & 4 deletions types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestWasmMsgInstantiateSerialization(t *testing.T) {
require.Equal(t, "", msg.Instantiate.Admin)
require.Equal(t, uint64(7897), msg.Instantiate.CodeID)
require.Equal(t, []byte(`{"claim":{}}`), msg.Instantiate.Msg)
require.Equal(t, Coins{
require.Equal(t, Array[Coin]{
{"stones", "321"},
}, msg.Instantiate.Funds)
require.Equal(t, "my instance", msg.Instantiate.Label)
Expand All @@ -47,7 +47,7 @@ func TestWasmMsgInstantiateSerialization(t *testing.T) {
require.Equal(t, "king", msg.Instantiate.Admin)
require.Equal(t, uint64(7897), msg.Instantiate.CodeID)
require.Equal(t, []byte(`{"claim":{}}`), msg.Instantiate.Msg)
require.Equal(t, Coins{
require.Equal(t, Array[Coin]{
{"stones", "321"},
}, msg.Instantiate.Funds)
require.Equal(t, "my instance", msg.Instantiate.Label)
Expand All @@ -70,7 +70,7 @@ func TestWasmMsgInstantiate2Serialization(t *testing.T) {
require.Equal(t, "", msg.Instantiate2.Admin)
require.Equal(t, uint64(7897), msg.Instantiate2.CodeID)
require.Equal(t, []byte(`{"claim":{}}`), msg.Instantiate2.Msg)
require.Equal(t, Coins{
require.Equal(t, Array[Coin]{
{"stones", "321"},
}, msg.Instantiate2.Funds)
require.Equal(t, "my instance", msg.Instantiate2.Label)
Expand Down Expand Up @@ -161,5 +161,5 @@ func TestMsgFundCommunityPoolSerialization(t *testing.T) {
err := json.Unmarshal(document, &msg)
require.NoError(t, err)

require.Equal(t, Coins{{"adenom", "300"}, {"bdenom", "400"}}, msg.FundCommunityPool.Amount)
require.Equal(t, Array[Coin]{{"adenom", "300"}, {"bdenom", "400"}}, msg.FundCommunityPool.Amount)
}
12 changes: 6 additions & 6 deletions types/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ type AllBalancesQuery struct {

// AllBalancesResponse is the expected response to AllBalancesQuery
type AllBalancesResponse struct {
Amount Coins `json:"amount"`
Amount Array[Coin] `json:"amount"`
}

type DenomMetadataQuery struct {
Expand Down Expand Up @@ -320,11 +320,11 @@ type DelegationResponse struct {
}

type FullDelegation struct {
Delegator string `json:"delegator"`
Validator string `json:"validator"`
Amount Coin `json:"amount"`
AccumulatedRewards Coins `json:"accumulated_rewards"`
CanRedelegate Coin `json:"can_redelegate"`
Delegator string `json:"delegator"`
Validator string `json:"validator"`
Amount Coin `json:"amount"`
AccumulatedRewards Array[Coin] `json:"accumulated_rewards"`
CanRedelegate Coin `json:"can_redelegate"`
}

type BondedDenomResponse struct {
Expand Down
Loading

0 comments on commit 4bef84b

Please sign in to comment.