Skip to content

Commit 320236a

Browse files
committed
replace erc20 native coin's prefix
from: erc20/ to: erc20
1 parent 9f3f1e7 commit 320236a

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

x/erc20/keeper/integration_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package keeper_test
22

33
import (
4-
"fmt"
54
"math/big"
65
"testing"
76

@@ -183,7 +182,7 @@ var _ = Describe("ERC20:", Ordered, func() {
183182
})
184183

185184
It("should send coins to the receiver account", func() {
186-
balRes, err := s.handler.GetBalanceFromBank(s.keyring.GetAccAddr(0), fmt.Sprintf("erc20/%s", contract.Hex()))
185+
balRes, err := s.handler.GetBalanceFromBank(s.keyring.GetAccAddr(0), types.ModuleName+contract.Hex())
187186
Expect(err).To(BeNil())
188187
balanceCoin := balRes.Balance
189188
Expect(balanceCoin.Amount).To(Equal(amt))

x/erc20/types/proposal.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,22 @@ func CreateDenomDescription(address string) string {
4141

4242
// CreateDenom generates a string the module name plus the address to avoid conflicts with names staring with a number
4343
func CreateDenom(address string) string {
44-
return fmt.Sprintf("%s/%s", ModuleName, address)
44+
return fmt.Sprintf("%s%s", ModuleName, address)
4545
}
4646

47-
// ValidateErc20Denom checks if a denom is a valid erc20/
48-
// denomination
47+
// ValidateErc20Denom checks if a denom is a valid erc20 denomination.
48+
// Example: "erc200xabc..."
4949
func ValidateErc20Denom(denom string) error {
50-
denomSplit := strings.SplitN(denom, "/", 2)
51-
52-
if len(denomSplit) != 2 || denomSplit[0] != ModuleName {
53-
return fmt.Errorf("invalid denom. %s denomination should be prefixed with the format 'erc20/", denom)
50+
if strings.HasPrefix(denom, ModuleName) {
51+
trimmed := strings.TrimPrefix(denom, ModuleName)
52+
if len(trimmed) > 0 && trimmed[0] == '/' {
53+
// backward compatibility with old denom format ("erc20/0xabc...")
54+
return cosmosevmtypes.ValidateAddress(trimmed[1:])
55+
}
56+
return cosmosevmtypes.ValidateAddress(trimmed)
5457
}
5558

56-
return cosmosevmtypes.ValidateAddress(denomSplit[1])
59+
return fmt.Errorf("invalid denom. %s denomination should be prefixed with the format 'erc20", denom)
5760
}
5861

5962
// NewRegisterERC20Proposal returns new instance of RegisterERC20Proposal

x/erc20/types/proposal_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ func (suite *ProposalTestSuite) TestCreateDenom() {
5959
{
6060
"with valid address",
6161
"0xdac17f958d2ee523a2206206994597c13d831ec7",
62-
"erc20/0xdac17f958d2ee523a2206206994597c13d831ec7",
62+
"erc200xdac17f958d2ee523a2206206994597c13d831ec7",
6363
},
6464
{
6565
"with empty string",
6666
"",
67-
"erc20/",
67+
"erc20",
6868
},
6969
}
7070
for _, tc := range testCases {
@@ -79,6 +79,11 @@ func (suite *ProposalTestSuite) TestValidateErc20Denom() {
7979
denom string
8080
expPass bool
8181
}{
82+
{
83+
"fail: invalid address",
84+
"0xdac17f958d2ee523a22",
85+
false,
86+
},
8287
{
8388
"- instead of /",
8489
"erc20-0xdac17f958d2ee523a2206206994597c13d831ec7",
@@ -104,6 +109,11 @@ func (suite *ProposalTestSuite) TestValidateErc20Denom() {
104109
"erc20/0xdac17f958d2ee523a2206206994597c13d831ec7",
105110
true,
106111
},
112+
{
113+
"pass",
114+
"erc200xdac17f958d2ee523a2206206994597c13d831ec7",
115+
true,
116+
},
107117
}
108118
for _, tc := range testCases {
109119
err := types.ValidateErc20Denom(tc.denom)

x/ibc/transfer/keeper/msg_server_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/cosmos/evm/testutil/integration/os/keyring"
99
testutils "github.com/cosmos/evm/testutil/integration/os/utils"
10+
erc20types "github.com/cosmos/evm/x/erc20/types"
1011
"github.com/cosmos/evm/x/ibc/transfer/keeper"
1112
evmtypes "github.com/cosmos/evm/x/vm/types"
1213
"github.com/cosmos/ibc-go/v10/modules/apps/transfer/types"
@@ -55,7 +56,7 @@ func (suite *KeeperTestSuite) TestTransfer() {
5556
contractAddr, err := suite.DeployContract("coin", "token", uint8(6))
5657
suite.Require().NoError(err)
5758

58-
transferMsg := types.NewMsgTransfer(types.PortID, chan0, sdk.NewCoin("erc20/"+contractAddr.String(), math.NewInt(10)), addr, receiver.String(), timeoutHeight, 0, "")
59+
transferMsg := types.NewMsgTransfer(types.PortID, chan0, sdk.NewCoin(erc20types.ModuleName+contractAddr.String(), math.NewInt(10)), addr, receiver.String(), timeoutHeight, 0, "")
5960
return transferMsg
6061
},
6162
false,
@@ -189,7 +190,7 @@ func (suite *KeeperTestSuite) TestTransfer() {
189190
suite.Require().NoError(err)
190191
suite.Require().True(len(res) == 1)
191192
pair := res[0]
192-
suite.Require().Equal("erc20/"+pair.Erc20Address, pair.Denom)
193+
suite.Require().Equal(erc20types.ModuleName+pair.Erc20Address, pair.Denom)
193194

194195
amt := math.NewInt(10)
195196
_, err = suite.MintERC20Token(contractAddr, sender.Addr, amt.BigInt())

0 commit comments

Comments
 (0)