From 95a033f7f6c9c13a61a0e8ffa4a443cc05718e8b Mon Sep 17 00:00:00 2001 From: dreamer Date: Mon, 29 Apr 2024 18:08:02 +0800 Subject: [PATCH] support ibc token --- modules/token/types/v1/msgs.go | 2 +- modules/token/types/v1/msgs_test.go | 32 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/modules/token/types/v1/msgs.go b/modules/token/types/v1/msgs.go index c89ce5f3..251489ca 100644 --- a/modules/token/types/v1/msgs.go +++ b/modules/token/types/v1/msgs.go @@ -39,7 +39,7 @@ var ( _ sdk.Msg = &MsgSwapToERC20{} _ sdk.Msg = &MsgUpgradeERC20{} - regexpERC20Fmt = fmt.Sprintf("^[a-z][a-z0-9/]{%d,%d}$", tokentypes.MinimumSymbolLen-1, tokentypes.MaximumSymbolLen-1) + regexpERC20Fmt = fmt.Sprintf("^[a-z][a-zA-Z0-9/]{%d,%d}$", tokentypes.MinimumSymbolLen-1, 100) regexpERC20 = regexp.MustCompile(regexpERC20Fmt).MatchString ) diff --git a/modules/token/types/v1/msgs_test.go b/modules/token/types/v1/msgs_test.go index 994d29f2..ed208fea 100644 --- a/modules/token/types/v1/msgs_test.go +++ b/modules/token/types/v1/msgs_test.go @@ -259,3 +259,35 @@ func TestMsgTransferTokenOwnerValidation(t *testing.T) { } } } + +func TestMsgDeployERC20(t *testing.T) { + testData := []struct { + symbol string + name string + scale uint32 + minUnit string + authority string + expectPass bool + }{ + {symbol: "btc", name: "BTC TOKEN", scale: 18, minUnit: "staoshi", authority: addr1, expectPass: true}, + {symbol: "BTC", name: "BTC TOKEN", scale: 18, minUnit: "staoshi", authority: addr1, expectPass: false}, + {symbol: "bTC", name: "BTC TOKEN", scale: 18, minUnit: "staoshi", authority: addr1, expectPass: true}, + {symbol: "stake", name: "Stake Token", scale: 18, minUnit: "ibc/3C3D7B3BE4ECC85A0E5B52A3AEC3B7DFC2AA9CA47C37821E57020D6807043BE9", authority: addr1, expectPass: true}, + {symbol: "ibc/3C3D7B3BE4ECC85A0E5B52A3AEC3B7DFC2AA9CA47C37821E57020D6807043BE9", name: "Stake Token", scale: 18, minUnit: "ibc/3C3D7B3BE4ECC85A0E5B52A3AEC3B7DFC2AA9CA47C37821E57020D6807043BE9", authority: addr1, expectPass: true}, + } + + for _, td := range testData { + msg := MsgDeployERC20{ + Symbol: td.symbol, + Name: td.name, + Scale: td.scale, + MinUnit: td.minUnit, + Authority: td.authority, + } + if td.expectPass { + require.Nil(t, msg.ValidateBasic(), "test: %v", td.name) + } else { + require.NotNil(t, msg.ValidateBasic(), "test: %v", td.name) + } + } +}