Skip to content

Commit

Permalink
update foreignCoinsList -> foreignCoinList & test
Browse files Browse the repository at this point in the history
  • Loading branch information
chixiaowen committed Nov 18, 2023
1 parent 763ffba commit fb756ef
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion proto/fungible/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ option go_package = "github.com/zeta-chain/zetacore/x/fungible/types";
// GenesisState defines the fungible module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
repeated ForeignCoin foreignCoinsList = 2 [(gogoproto.nullable) = false];
repeated ForeignCoin foreignCoinList = 2 [(gogoproto.nullable) = false];
SystemContract systemContract = 3;
}
4 changes: 2 additions & 2 deletions x/crosschain/keeper/cctx_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func TestGetRevertGasLimit(t *testing.T) {

chainID := getValidEthChainID(t)

zk.FungibleKeeper.SetForeignCoins(ctx, fungibletypes.ForeignCoins{
zk.FungibleKeeper.SetForeignCoins(ctx, fungibletypes.ForeignCoin{
Zrc20ContractAddress: sample.EthAddress().String(),
ForeignChainId: chainID,
CoinType: common.CoinType_Gas,
Expand Down Expand Up @@ -261,7 +261,7 @@ func TestGetRevertGasLimit(t *testing.T) {
chainID := getValidEthChainID(t)
asset := sample.EthAddress().String()

zk.FungibleKeeper.SetForeignCoins(ctx, fungibletypes.ForeignCoins{
zk.FungibleKeeper.SetForeignCoins(ctx, fungibletypes.ForeignCoin{
Zrc20ContractAddress: sample.EthAddress().String(),
ForeignChainId: chainID,
CoinType: common.CoinType_ERC20,
Expand Down
4 changes: 2 additions & 2 deletions x/fungible/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
// Set all the foreignCoins
for _, elem := range genState.ForeignCoinsList {
for _, elem := range genState.ForeignCoinList {
k.SetForeignCoins(ctx, elem)
}
// Set if defined
Expand All @@ -26,7 +26,7 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
var genesis types.GenesisState

genesis.Params = k.GetParams(ctx)
genesis.ForeignCoinsList = k.GetAllForeignCoins(ctx)
genesis.ForeignCoinList = k.GetAllForeignCoins(ctx)

// Get all zetaDepositAndCallContract
system, found := k.GetSystemContract(ctx)
Expand Down
2 changes: 1 addition & 1 deletion x/fungible/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func TestGenesis(t *testing.T) {
genesisState := types.GenesisState{
Params: types.DefaultParams(),
ForeignCoinsList: []types.ForeignCoins{
ForeignCoinList: []types.ForeignCoin{
sample.ForeignCoins(t, sample.EthAddress().String()),
sample.ForeignCoins(t, sample.EthAddress().String()),
sample.ForeignCoins(t, sample.EthAddress().String()),
Expand Down
28 changes: 14 additions & 14 deletions x/fungible/keeper/foreign_coins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/zeta-chain/zetacore/x/fungible/types"
)

func createNForeignCoins(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.ForeignCoins {
items := make([]types.ForeignCoins, n)
func createNForeignCoins(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.ForeignCoin {
items := make([]types.ForeignCoin, n)
for i := range items {
items[i].Zrc20ContractAddress = strconv.Itoa(i)

Expand All @@ -24,7 +24,7 @@ func createNForeignCoins(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.
return items
}

func setForeignCoins(ctx sdk.Context, k *keeper.Keeper, fc ...types.ForeignCoins) {
func setForeignCoins(ctx sdk.Context, k *keeper.Keeper, fc ...types.ForeignCoin) {
for _, item := range fc {
k.SetForeignCoins(ctx, item)
}
Expand All @@ -35,31 +35,31 @@ func TestKeeper_GetGasCoinForForeignCoin(t *testing.T) {

// populate
setForeignCoins(ctx, k,
types.ForeignCoins{
types.ForeignCoin{
Zrc20ContractAddress: sample.EthAddress().String(),
ForeignChainId: 1,
CoinType: common.CoinType_ERC20,
Name: "foo",
},
types.ForeignCoins{
types.ForeignCoin{
Zrc20ContractAddress: sample.EthAddress().String(),
ForeignChainId: 1,
CoinType: common.CoinType_ERC20,
Name: "foo",
},
types.ForeignCoins{
types.ForeignCoin{
Zrc20ContractAddress: sample.EthAddress().String(),
ForeignChainId: 1,
CoinType: common.CoinType_Gas,
Name: "bar",
},
types.ForeignCoins{
types.ForeignCoin{
Zrc20ContractAddress: sample.EthAddress().String(),
ForeignChainId: 2,
CoinType: common.CoinType_ERC20,
Name: "foo",
},
types.ForeignCoins{
types.ForeignCoin{
Zrc20ContractAddress: sample.EthAddress().String(),
ForeignChainId: 2,
CoinType: common.CoinType_ERC20,
Expand All @@ -84,35 +84,35 @@ func TestKeeperGetForeignCoinFromAsset(t *testing.T) {

// populate
setForeignCoins(ctx, k,
types.ForeignCoins{
types.ForeignCoin{
Zrc20ContractAddress: sample.EthAddress().String(),
Asset: sample.EthAddress().String(),
ForeignChainId: 1,
CoinType: common.CoinType_ERC20,
Name: "foo",
},
types.ForeignCoins{
types.ForeignCoin{
Zrc20ContractAddress: sample.EthAddress().String(),
Asset: gasAsset,
ForeignChainId: 1,
CoinType: common.CoinType_ERC20,
Name: "bar",
},
types.ForeignCoins{
types.ForeignCoin{
Zrc20ContractAddress: sample.EthAddress().String(),
Asset: sample.EthAddress().String(),
ForeignChainId: 1,
CoinType: common.CoinType_Gas,
Name: "foo",
},
types.ForeignCoins{
types.ForeignCoin{
Zrc20ContractAddress: sample.EthAddress().String(),
Asset: sample.EthAddress().String(),
ForeignChainId: 2,
CoinType: common.CoinType_ERC20,
Name: "foo",
},
types.ForeignCoins{
types.ForeignCoin{
Zrc20ContractAddress: sample.EthAddress().String(),
Asset: sample.EthAddress().String(),
ForeignChainId: 2,
Expand All @@ -138,7 +138,7 @@ func TestKeeperGetForeignCoinFromAsset(t *testing.T) {
k, ctx, _, _ := keepertest.FungibleKeeper(t)

setForeignCoins(ctx, k,
types.ForeignCoins{
types.ForeignCoin{
Zrc20ContractAddress: sample.EthAddress().String(),
Asset: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
ForeignChainId: 1,
Expand Down
14 changes: 7 additions & 7 deletions x/fungible/keeper/grpc_query_foreign_coins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ func TestForeignCoinsQuerySingle(t *testing.T) {
request: &types.QueryGetForeignCoinsRequest{
Index: msgs[0].Zrc20ContractAddress,
},
response: &types.QueryGetForeignCoinsResponse{ForeignCoins: msgs[0]},
response: &types.QueryGetForeignCoinsResponse{ForeignCoin: msgs[0]},
},
{
desc: "Second",
request: &types.QueryGetForeignCoinsRequest{
Index: msgs[1].Zrc20ContractAddress,
},
response: &types.QueryGetForeignCoinsResponse{ForeignCoins: msgs[1]},
response: &types.QueryGetForeignCoinsResponse{ForeignCoin: msgs[1]},
},
{
desc: "KeyNotFound",
Expand Down Expand Up @@ -86,10 +86,10 @@ func TestForeignCoinsQueryPaginated(t *testing.T) {
for i := 0; i < len(msgs); i += step {
resp, err := keeper.ForeignCoinsAll(wctx, request(nil, uint64(i), uint64(step), false))
require.NoError(t, err)
require.LessOrEqual(t, len(resp.ForeignCoins), step)
require.LessOrEqual(t, len(resp.ForeignCoin), step)
require.Subset(t,
nullify.Fill(msgs),
nullify.Fill(resp.ForeignCoins),
nullify.Fill(resp.ForeignCoin),
)
}
})
Expand All @@ -99,10 +99,10 @@ func TestForeignCoinsQueryPaginated(t *testing.T) {
for i := 0; i < len(msgs); i += step {
resp, err := keeper.ForeignCoinsAll(wctx, request(next, 0, uint64(step), false))
require.NoError(t, err)
require.LessOrEqual(t, len(resp.ForeignCoins), step)
require.LessOrEqual(t, len(resp.ForeignCoin), step)
require.Subset(t,
nullify.Fill(msgs),
nullify.Fill(resp.ForeignCoins),
nullify.Fill(resp.ForeignCoin),
)
next = resp.Pagination.NextKey
}
Expand All @@ -113,7 +113,7 @@ func TestForeignCoinsQueryPaginated(t *testing.T) {
require.Equal(t, len(msgs), int(resp.Pagination.Total))
require.ElementsMatch(t,
nullify.Fill(msgs),
nullify.Fill(resp.ForeignCoins),
nullify.Fill(resp.ForeignCoin),
)
})
t.Run("InvalidRequest", func(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions x/fungible/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
// DefaultGenesis returns the default fungible genesis state
func DefaultGenesis() *GenesisState {
return &GenesisState{
ForeignCoinsList: []ForeignCoin{},
SystemContract: nil,
Params: DefaultParams(),
ForeignCoinList: []ForeignCoin{},
SystemContract: nil,
Params: DefaultParams(),
}
}

Expand All @@ -19,7 +19,7 @@ func (gs GenesisState) Validate() error {
// Check for duplicated index in foreignCoins
foreignCoinsIndexMap := make(map[string]struct{})

for _, elem := range gs.ForeignCoinsList {
for _, elem := range gs.ForeignCoinList {
index := string(ForeignCoinsKey(elem.Zrc20ContractAddress))
if _, ok := foreignCoinsIndexMap[index]; ok {
return fmt.Errorf("duplicated index for foreignCoins")
Expand Down
50 changes: 25 additions & 25 deletions x/fungible/types/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions x/fungible/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestGenesisState_Validate(t *testing.T) {
desc: "valid genesis state",
genState: &types.GenesisState{

ForeignCoinsList: []types.ForeignCoin{
ForeignCoinList: []types.ForeignCoin{
{
Zrc20ContractAddress: "0",
},
Expand All @@ -36,7 +36,7 @@ func TestGenesisState_Validate(t *testing.T) {
{
desc: "duplicated foreignCoins",
genState: &types.GenesisState{
ForeignCoinsList: []types.ForeignCoin{
ForeignCoinList: []types.ForeignCoin{
{
Zrc20ContractAddress: "0",
},
Expand Down

0 comments on commit fb756ef

Please sign in to comment.