This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
forked from 0xPolygon/polygon-edge
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow providing mintable native token owner account (0xPolygon#1603)
* Allow providing mintable native token owner account * Fix test * Fix * Add extractNativeTokenMetadata unit test
- Loading branch information
1 parent
827b08b
commit c5ebc40
Showing
8 changed files
with
167 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package genesis | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/0xPolygon/polygon-edge/consensus/polybft" | ||
"github.com/0xPolygon/polygon-edge/types" | ||
) | ||
|
||
func Test_extractNativeTokenMetadata(t *testing.T) { | ||
t.Parallel() | ||
|
||
cases := []struct { | ||
name string | ||
rawConfig string | ||
expectedCfg *polybft.TokenConfig | ||
expectErr bool | ||
}{ | ||
{ | ||
name: "default token config", | ||
rawConfig: "", | ||
expectedCfg: &polybft.TokenConfig{ | ||
Name: defaultNativeTokenName, | ||
Symbol: defaultNativeTokenSymbol, | ||
Decimals: defaultNativeTokenDecimals, | ||
IsMintable: false, | ||
Owner: types.ZeroAddress, | ||
}, | ||
expectErr: false, | ||
}, | ||
{ | ||
name: "not enough params provided", | ||
rawConfig: "Test:TST:18", | ||
expectErr: true, | ||
}, | ||
{ | ||
name: "empty name provided", | ||
rawConfig: ":TST:18:false", | ||
expectErr: true, | ||
}, | ||
{ | ||
name: "empty symbol provided", | ||
rawConfig: "Test::18:false", | ||
expectErr: true, | ||
}, | ||
{ | ||
name: "invalid decimals number provided", | ||
rawConfig: "Test:TST:9999999999999999999999999999999999999999999999999999999999:false", | ||
expectErr: true, | ||
}, | ||
{ | ||
name: "invalid mintable flag provided", | ||
rawConfig: "Test:TST:18:bar", | ||
expectErr: true, | ||
}, | ||
{ | ||
name: "mintable token not enough params provided", | ||
rawConfig: "Test:TST:18:true", | ||
expectErr: true, | ||
}, | ||
{ | ||
name: "non-mintable valid config", | ||
rawConfig: "MyToken:MTK:9:false", | ||
expectedCfg: &polybft.TokenConfig{ | ||
Name: "MyToken", | ||
Symbol: "MTK", | ||
Decimals: 9, | ||
IsMintable: false, | ||
Owner: types.ZeroAddress, | ||
}, | ||
expectErr: false, | ||
}, | ||
{ | ||
name: "non-mintable token config, owner provided but ignored", | ||
rawConfig: "MyToken:MTK:9:false:0x123456789", | ||
expectedCfg: &polybft.TokenConfig{ | ||
Name: "MyToken", | ||
Symbol: "MTK", | ||
Decimals: 9, | ||
IsMintable: false, | ||
Owner: types.ZeroAddress, | ||
}, | ||
expectErr: false, | ||
}, | ||
{ | ||
name: "mintable token valid config", | ||
rawConfig: "MyMintToken:MMTK:9:true:0x123456789", | ||
expectedCfg: &polybft.TokenConfig{ | ||
Name: "MyMintToken", | ||
Symbol: "MMTK", | ||
Decimals: 9, | ||
IsMintable: true, | ||
Owner: types.StringToAddress("0x123456789"), | ||
}, | ||
expectErr: false, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
c := c | ||
t.Run(c.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
p := &genesisParams{nativeTokenConfigRaw: c.rawConfig} | ||
err := p.extractNativeTokenMetadata() | ||
|
||
if c.expectErr { | ||
require.Error(t, err) | ||
require.Nil(t, p.nativeTokenConfig) | ||
} else { | ||
require.NoError(t, err) | ||
require.Equal(t, c.expectedCfg, p.nativeTokenConfig) | ||
} | ||
}) | ||
} | ||
} |
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