0g-chain/chaincfg/denoms_test.go

81 lines
1.5 KiB
Go
Raw Normal View History

2024-05-09 11:35:16 +00:00
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
}{
{
2024-05-10 06:31:49 +00:00
"standard to gas",
2024-05-09 11:35:16 +00:00
MakeCoinForStandardDenom(99),
2024-05-10 06:31:49 +00:00
GasDenom,
MakeCoinForGasDenom(99 * (EvmDenomConversionMultiplier / GasDenomConversionMultiplier)),
2024-05-09 11:35:16 +00:00
nil,
},
{
2024-05-10 06:31:49 +00:00
"gas to standard",
MakeCoinForGasDenom(5e7),
2024-05-09 11:35:16 +00:00
StandardDenom,
MakeCoinForStandardDenom(50),
nil,
},
{
"standard to base",
MakeCoinForStandardDenom(22),
2024-05-10 06:31:49 +00:00
EvmDenom,
MakeCoinForEvmDenom(22 * EvmDenomConversionMultiplier),
2024-05-09 11:35:16 +00:00
nil,
},
{
"base to standard",
2024-05-10 06:31:49 +00:00
MakeCoinForEvmDenom("97000000000000000000"),
2024-05-09 11:35:16 +00:00
StandardDenom,
MakeCoinForStandardDenom(97),
nil,
},
{
2024-05-10 06:31:49 +00:00
"gas to base",
MakeCoinForGasDenom(33),
EvmDenom,
MakeCoinForEvmDenom(33 * GasDenomConversionMultiplier),
2024-05-09 11:35:16 +00:00
nil,
},
{
2024-05-10 06:31:49 +00:00
"base to gas",
MakeCoinForEvmDenom("770000000000000"),
GasDenom,
MakeCoinForGasDenom(770000000000000 / GasDenomConversionMultiplier),
2024-05-09 11:35:16 +00:00
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)
})
}
}