mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 10:05:18 +00:00
81 lines
1.6 KiB
Go
81 lines
1.6 KiB
Go
package chaincfg
|
|
|
|
import (
|
|
"testing"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRegisterDenoms(t *testing.T) {
|
|
RegisterDenoms()
|
|
tests := []struct {
|
|
name string
|
|
from sdk.Coin
|
|
targetDenom string
|
|
expCoin sdk.Coin
|
|
expErr error
|
|
}{
|
|
{
|
|
"standard to auxiliary",
|
|
MakeCoinForStandardDenom(99),
|
|
AuxiliaryDenom,
|
|
MakeCoinForAuxiliaryDenom(99 * (BaseDenomConversionMultiplier / AuxiliaryDenomConversionMultiplier)),
|
|
nil,
|
|
},
|
|
{
|
|
"auxiliary to standard",
|
|
MakeCoinForAuxiliaryDenom(5e7),
|
|
StandardDenom,
|
|
MakeCoinForStandardDenom(50),
|
|
nil,
|
|
},
|
|
{
|
|
"standard to base",
|
|
MakeCoinForStandardDenom(22),
|
|
BaseDenom,
|
|
MakeCoinForBaseDenom(22 * BaseDenomConversionMultiplier),
|
|
nil,
|
|
},
|
|
{
|
|
"base to standard",
|
|
MakeCoinForBaseDenom("97000000000000000000"),
|
|
StandardDenom,
|
|
MakeCoinForStandardDenom(97),
|
|
nil,
|
|
},
|
|
{
|
|
"auxiliary to base",
|
|
MakeCoinForAuxiliaryDenom(33),
|
|
BaseDenom,
|
|
MakeCoinForBaseDenom(33 * AuxiliaryDenomConversionMultiplier),
|
|
nil,
|
|
},
|
|
{
|
|
"base to auxiliary",
|
|
MakeCoinForBaseDenom("770000000000000"),
|
|
AuxiliaryDenom,
|
|
MakeCoinForAuxiliaryDenom(770000000000000 / AuxiliaryDenomConversionMultiplier),
|
|
nil,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
ret, err := sdk.ConvertCoin(tt.from, tt.targetDenom)
|
|
if tt.expErr != nil {
|
|
if err == nil {
|
|
t.Errorf("expErr is not nil, but got nil")
|
|
return
|
|
}
|
|
} else {
|
|
if err != nil {
|
|
t.Errorf("expErr is nil, but got %v", err)
|
|
return
|
|
}
|
|
}
|
|
|
|
assert.Equal(t, tt.expCoin, ret)
|
|
})
|
|
}
|
|
}
|