-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1645 from oasisprotocol/kostko/feature/cfg-consen…
…sus-denom client-sdk/go: Add consensus denomination config
- Loading branch information
Showing
3 changed files
with
119 additions
and
8 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,90 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestValidateParaTime(t *testing.T) { | ||
require := require.New(t) | ||
|
||
p := ParaTime{ | ||
Description: "Test ParaTime.", | ||
ID: "000000000000000000000000000000000000000000000000f80306c9858e7279", | ||
Denominations: map[string]*DenominationInfo{ | ||
NativeDenominationKey: { | ||
Symbol: "FOO", | ||
Decimals: 18, | ||
}, | ||
"BAR": { | ||
Symbol: "BARfoo", | ||
Decimals: 9, | ||
}, | ||
}, | ||
} | ||
err := p.Validate() | ||
require.NoError(err, "Validate should succeed with valid configuration") | ||
|
||
p.ConsensusDenomination = NativeDenominationKey | ||
err = p.Validate() | ||
require.NoError(err, "Validate should succeed with valid consensus denomination") | ||
p.ConsensusDenomination = "BAR" | ||
err = p.Validate() | ||
require.NoError(err, "Validate should succeed with valid consensus denomination") | ||
|
||
invalid := p | ||
invalid.ID = "invalid" | ||
err = invalid.Validate() | ||
require.Error(err, "Validate should fail with invalid ID") | ||
|
||
invalid = p | ||
invalid.ConsensusDenomination = "invalid" | ||
err = invalid.Validate() | ||
require.Error(err, "Validate should fail with invalid consensus denomination") | ||
} | ||
|
||
func TestDenominationInfo(t *testing.T) { | ||
require := require.New(t) | ||
|
||
p := ParaTime{ | ||
Description: "Test ParaTime.", | ||
ID: "000000000000000000000000000000000000000000000000f80306c9858e7279", | ||
Denominations: map[string]*DenominationInfo{ | ||
NativeDenominationKey: { | ||
Symbol: "FOO", | ||
Decimals: 18, | ||
}, | ||
"BAR": { | ||
Symbol: "BARfoo", | ||
Decimals: 9, | ||
}, | ||
"low": { | ||
Symbol: "LOWfoo", | ||
Decimals: 9, | ||
}, | ||
}, | ||
} | ||
err := p.Validate() | ||
require.NoError(err, "Validate should succeed with valid configuration") | ||
|
||
di := p.GetDenominationInfo("") | ||
require.NotNil(di, "GetDenominationInfo should return a non-nil denomination info") | ||
require.Equal(di.Symbol, "FOO") | ||
require.EqualValues(di.Decimals, 18) | ||
|
||
di = p.GetDenominationInfo("BAR") | ||
require.NotNil(di, "GetDenominationInfo should return a non-nil denomination info") | ||
require.Equal(di.Symbol, "BARfoo") | ||
require.EqualValues(di.Decimals, 9) | ||
|
||
di = p.GetDenominationInfo("LOW") | ||
require.NotNil(di, "GetDenominationInfo should return a non-nil denomination info") | ||
require.Equal(di.Symbol, "LOWfoo") | ||
require.EqualValues(di.Decimals, 9) | ||
|
||
di = p.GetDenominationInfo("DEFAULT") | ||
require.NotNil(di, "GetDenominationInfo should return a non-nil denomination info") | ||
require.Equal(di.Symbol, "DEFAULT") | ||
require.EqualValues(di.Decimals, 9) | ||
} |