From fb756eff6bb67e5f31e89aaf316449c3aa986c72 Mon Sep 17 00:00:00 2001 From: chixiaowen <940313784@qq.com> Date: Sat, 18 Nov 2023 11:40:47 +0800 Subject: [PATCH] update foreignCoinsList -> foreignCoinList & test --- proto/fungible/genesis.proto | 2 +- x/crosschain/keeper/cctx_utils_test.go | 4 +- x/fungible/genesis.go | 4 +- x/fungible/genesis_test.go | 2 +- x/fungible/keeper/foreign_coins_test.go | 28 +++++------ .../keeper/grpc_query_foreign_coins_test.go | 14 +++--- x/fungible/types/genesis.go | 8 +-- x/fungible/types/genesis.pb.go | 50 +++++++++---------- x/fungible/types/genesis_test.go | 4 +- 9 files changed, 58 insertions(+), 58 deletions(-) diff --git a/proto/fungible/genesis.proto b/proto/fungible/genesis.proto index 2b11d32000..8cf1c3f933 100644 --- a/proto/fungible/genesis.proto +++ b/proto/fungible/genesis.proto @@ -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; } diff --git a/x/crosschain/keeper/cctx_utils_test.go b/x/crosschain/keeper/cctx_utils_test.go index 2d122bce7a..e009b11183 100644 --- a/x/crosschain/keeper/cctx_utils_test.go +++ b/x/crosschain/keeper/cctx_utils_test.go @@ -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, @@ -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, diff --git a/x/fungible/genesis.go b/x/fungible/genesis.go index 59b54fe6da..d43067fdc9 100644 --- a/x/fungible/genesis.go +++ b/x/fungible/genesis.go @@ -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 @@ -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) diff --git a/x/fungible/genesis_test.go b/x/fungible/genesis_test.go index 119e862a18..412b66630b 100644 --- a/x/fungible/genesis_test.go +++ b/x/fungible/genesis_test.go @@ -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()), diff --git a/x/fungible/keeper/foreign_coins_test.go b/x/fungible/keeper/foreign_coins_test.go index 0a5a0f37f0..adb9d355e1 100644 --- a/x/fungible/keeper/foreign_coins_test.go +++ b/x/fungible/keeper/foreign_coins_test.go @@ -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) @@ -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) } @@ -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, @@ -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, @@ -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, diff --git a/x/fungible/keeper/grpc_query_foreign_coins_test.go b/x/fungible/keeper/grpc_query_foreign_coins_test.go index 76b4b2e7c0..06db7a97aa 100644 --- a/x/fungible/keeper/grpc_query_foreign_coins_test.go +++ b/x/fungible/keeper/grpc_query_foreign_coins_test.go @@ -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", @@ -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), ) } }) @@ -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 } @@ -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) { diff --git a/x/fungible/types/genesis.go b/x/fungible/types/genesis.go index 09e33600ee..6b2396e002 100644 --- a/x/fungible/types/genesis.go +++ b/x/fungible/types/genesis.go @@ -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(), } } @@ -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") diff --git a/x/fungible/types/genesis.pb.go b/x/fungible/types/genesis.pb.go index f387e04d20..eb8532fa49 100644 --- a/x/fungible/types/genesis.pb.go +++ b/x/fungible/types/genesis.pb.go @@ -26,9 +26,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the fungible module's genesis state. type GenesisState struct { - Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` - ForeignCoinsList []ForeignCoin `protobuf:"bytes,2,rep,name=foreignCoinsList,proto3" json:"foreignCoinsList"` - SystemContract *SystemContract `protobuf:"bytes,3,opt,name=systemContract,proto3" json:"systemContract,omitempty"` + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + ForeignCoinList []ForeignCoin `protobuf:"bytes,2,rep,name=foreignCoinList,proto3" json:"foreignCoinList"` + SystemContract *SystemContract `protobuf:"bytes,3,opt,name=systemContract,proto3" json:"systemContract,omitempty"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -71,9 +71,9 @@ func (m *GenesisState) GetParams() Params { return Params{} } -func (m *GenesisState) GetForeignCoinsList() []ForeignCoin { +func (m *GenesisState) GetForeignCoinList() []ForeignCoin { if m != nil { - return m.ForeignCoinsList + return m.ForeignCoinList } return nil } @@ -92,7 +92,7 @@ func init() { func init() { proto.RegisterFile("fungible/genesis.proto", fileDescriptor_11e46382f3a6d0c2) } var fileDescriptor_11e46382f3a6d0c2 = []byte{ - // 291 bytes of a gzipped FileDescriptorProto + // 292 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4b, 0x2b, 0xcd, 0x4b, 0xcf, 0x4c, 0xca, 0x49, 0xd5, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0xae, 0x4a, 0x2d, 0x49, 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x03, 0xb3, @@ -100,18 +100,18 @@ var fileDescriptor_11e46382f3a6d0c2 = []byte{ 0xf3, 0xe2, 0x93, 0xf3, 0x33, 0xf3, 0xa0, 0x5a, 0xa5, 0x44, 0xe1, 0xb2, 0x05, 0x89, 0x45, 0x89, 0xb9, 0x30, 0x61, 0x39, 0xb8, 0x70, 0x71, 0x65, 0x71, 0x49, 0x6a, 0x6e, 0x7c, 0x72, 0x7e, 0x5e, 0x49, 0x51, 0x62, 0x72, 0x09, 0x54, 0x5e, 0x24, 0x3d, 0x3f, 0x3d, 0x1f, 0xcc, 0xd4, 0x07, 0xb1, - 0x20, 0xa2, 0x4a, 0x4d, 0x4c, 0x5c, 0x3c, 0xee, 0x10, 0x97, 0x05, 0x97, 0x24, 0x96, 0xa4, 0x0a, + 0x20, 0xa2, 0x4a, 0x0d, 0x4c, 0x5c, 0x3c, 0xee, 0x10, 0x97, 0x05, 0x97, 0x24, 0x96, 0xa4, 0x0a, 0x39, 0x72, 0xb1, 0x41, 0x8c, 0x95, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x36, 0x52, 0xd6, 0xc3, 0xe3, - 0x52, 0xbd, 0x00, 0xb0, 0x52, 0x27, 0x96, 0x13, 0xf7, 0xe4, 0x19, 0x82, 0xa0, 0x1a, 0x85, 0xa2, - 0xb8, 0x04, 0xa0, 0xee, 0x76, 0x06, 0x39, 0xdb, 0x27, 0xb3, 0xb8, 0x44, 0x82, 0x49, 0x81, 0x59, - 0x83, 0xdb, 0x48, 0x03, 0xaf, 0x61, 0x6e, 0x08, 0x4d, 0x50, 0x13, 0x31, 0xcc, 0x11, 0x0a, 0xe6, - 0xe2, 0x83, 0x78, 0xcf, 0x19, 0xea, 0x3b, 0x09, 0x66, 0xb0, 0x33, 0xb5, 0xf1, 0x9a, 0x1c, 0x8c, - 0xa2, 0x25, 0x08, 0xcd, 0x08, 0x27, 0xcf, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, - 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5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x82, 0xd4, + 0xe2, 0x24, 0x36, 0x70, 0xa0, 0x1a, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x82, 0xa4, 0xc6, 0xbb, + 0xf6, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -146,10 +146,10 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x1a } - if len(m.ForeignCoinsList) > 0 { - for iNdEx := len(m.ForeignCoinsList) - 1; iNdEx >= 0; iNdEx-- { + if len(m.ForeignCoinList) > 0 { + for iNdEx := len(m.ForeignCoinList) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.ForeignCoinsList[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.ForeignCoinList[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -192,8 +192,8 @@ func (m *GenesisState) Size() (n int) { _ = l l = m.Params.Size() n += 1 + l + sovGenesis(uint64(l)) - if len(m.ForeignCoinsList) > 0 { - for _, e := range m.ForeignCoinsList { + if len(m.ForeignCoinList) > 0 { + for _, e := range m.ForeignCoinList { l = e.Size() n += 1 + l + sovGenesis(uint64(l)) } @@ -275,7 +275,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ForeignCoinsList", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ForeignCoinList", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -302,8 +302,8 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.ForeignCoinsList = append(m.ForeignCoinsList, ForeignCoin{}) - if err := m.ForeignCoinsList[len(m.ForeignCoinsList)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.ForeignCoinList = append(m.ForeignCoinList, ForeignCoin{}) + if err := m.ForeignCoinList[len(m.ForeignCoinList)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/fungible/types/genesis_test.go b/x/fungible/types/genesis_test.go index 0ef3321a44..0f0abe79c1 100644 --- a/x/fungible/types/genesis_test.go +++ b/x/fungible/types/genesis_test.go @@ -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", }, @@ -36,7 +36,7 @@ func TestGenesisState_Validate(t *testing.T) { { desc: "duplicated foreignCoins", genState: &types.GenesisState{ - ForeignCoinsList: []types.ForeignCoin{ + ForeignCoinList: []types.ForeignCoin{ { Zrc20ContractAddress: "0", },