-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fungible): implement
MsgUpdateZRC20Name
(#3541)
* initialize message * implement message * add migration authorization * e2e test * update changelog * change order admin test * complete test * fix test * comments
- Loading branch information
Showing
20 changed files
with
1,375 additions
and
78 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
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,54 @@ | ||
package e2etests | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/zeta-chain/node/e2e/runner" | ||
"github.com/zeta-chain/node/e2e/utils" | ||
fungibletypes "github.com/zeta-chain/node/x/fungible/types" | ||
) | ||
|
||
// TestUpdateZRC20Name tests updating name and symbol of a ZRC20 | ||
func TestUpdateZRC20Name(r *runner.E2ERunner, _ []string) { | ||
msg := fungibletypes.NewMsgUpdateZRC20Name( | ||
r.ZetaTxServer.MustGetAccountAddressFromName(utils.AdminPolicyName), | ||
r.ETHZRC20Addr.Hex(), | ||
"New ETH", | ||
"ETH.NEW", | ||
) | ||
res, err := r.ZetaTxServer.BroadcastTx(utils.AdminPolicyName, msg) | ||
require.NoError(r, err) | ||
|
||
r.Logger.Info("Update eth zrc20 bytecode tx hash: %s", res.TxHash) | ||
|
||
// Get new info of the ZRC20 | ||
newName, err := r.ETHZRC20.Name(&bind.CallOpts{}) | ||
require.NoError(r, err) | ||
require.Equal(r, "New ETH", newName) | ||
|
||
newSymbol, err := r.ETHZRC20.Symbol(&bind.CallOpts{}) | ||
require.NoError(r, err) | ||
require.Equal(r, "ETH.NEW", newSymbol) | ||
|
||
// try another zrc20 | ||
msg = fungibletypes.NewMsgUpdateZRC20Name( | ||
r.ZetaTxServer.MustGetAccountAddressFromName(utils.AdminPolicyName), | ||
r.ERC20ZRC20Addr.Hex(), | ||
"New USDT", | ||
"USDT.NEW", | ||
) | ||
res, err = r.ZetaTxServer.BroadcastTx(utils.AdminPolicyName, msg) | ||
require.NoError(r, err) | ||
|
||
r.Logger.Info("Update erc20 zrc20 bytecode tx hash: %s", res.TxHash) | ||
|
||
// Get new info of the ZRC20 | ||
newName, err = r.ERC20ZRC20.Name(&bind.CallOpts{}) | ||
require.NoError(r, err) | ||
require.Equal(r, "New USDT", newName) | ||
|
||
newSymbol, err = r.ERC20ZRC20.Symbol(&bind.CallOpts{}) | ||
require.NoError(r, err) | ||
require.Equal(r, "USDT.NEW", newSymbol) | ||
} |
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
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,62 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
cosmoserrors "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
ethcommon "github.com/ethereum/go-ethereum/common" | ||
|
||
authoritytypes "github.com/zeta-chain/node/x/authority/types" | ||
"github.com/zeta-chain/node/x/fungible/types" | ||
) | ||
|
||
// UpdateZRC20Name updates the name and/or the symbol of a zrc20 token | ||
func (k msgServer) UpdateZRC20Name( | ||
goCtx context.Context, | ||
msg *types.MsgUpdateZRC20Name, | ||
) (*types.MsgUpdateZRC20NameResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
// check signer permission | ||
err := k.GetAuthorityKeeper().CheckAuthorization(ctx, msg) | ||
if err != nil { | ||
return nil, cosmoserrors.Wrap(authoritytypes.ErrUnauthorized, err.Error()) | ||
} | ||
|
||
// check the zrc20 is valid | ||
zrc20Addr := ethcommon.HexToAddress(msg.Zrc20Address) | ||
if zrc20Addr == (ethcommon.Address{}) { | ||
return nil, cosmoserrors.Wrapf( | ||
sdkerrors.ErrInvalidAddress, | ||
"invalid zrc20 contract address (%s)", | ||
msg.Zrc20Address, | ||
) | ||
} | ||
|
||
// check the zrc20 exists | ||
_, found := k.GetForeignCoins(ctx, msg.Zrc20Address) | ||
if !found { | ||
return nil, cosmoserrors.Wrapf( | ||
types.ErrForeignCoinNotFound, | ||
"no foreign coin match requested zrc20 address (%s)", | ||
msg.Zrc20Address, | ||
) | ||
} | ||
|
||
// call the contract methods | ||
if msg.Name != "" { | ||
if err := k.ZRC20SetName(ctx, zrc20Addr, msg.Name); err != nil { | ||
return nil, cosmoserrors.Wrapf(types.ErrContractCall, "failed to update zrc20 name (%s)", err.Error()) | ||
} | ||
} | ||
|
||
if msg.Symbol != "" { | ||
if err = k.ZRC20SetSymbol(ctx, zrc20Addr, msg.Symbol); err != nil { | ||
return nil, cosmoserrors.Wrapf(types.ErrContractCall, "failed to update zrc20 symbol (%s)", err.Error()) | ||
} | ||
} | ||
|
||
return &types.MsgUpdateZRC20NameResponse{}, nil | ||
} |
Oops, something went wrong.