mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-14 12:05:18 +00:00
fix
This commit is contained in:
parent
a4d3dd98ef
commit
6aefc5fac9
@ -63,11 +63,11 @@ func (suite *SimulateRequestTestSuite) TestSimulateRequest() {
|
||||
bank.MsgSend{
|
||||
FromAddress: fromAddr,
|
||||
ToAddress: toAddr,
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
|
||||
},
|
||||
},
|
||||
Fee: auth.StdFee{
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(5e4))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(5e4))),
|
||||
Gas: 1e6,
|
||||
},
|
||||
Memo: "test memo",
|
||||
|
@ -60,7 +60,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100e6)),
|
||||
),
|
||||
},
|
||||
checkTx: false,
|
||||
@ -130,7 +130,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
||||
[]sdk.Msg{banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[3],
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100e6)),
|
||||
)}),
|
||||
},
|
||||
checkTx: false,
|
||||
@ -163,7 +163,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[3],
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100e6)),
|
||||
),
|
||||
&evmtypes.MsgEthereumTx{},
|
||||
},
|
||||
|
@ -157,7 +157,7 @@ func (suite *EIP712TestSuite) SetupTest() {
|
||||
// Genesis states
|
||||
evmGs := evmtypes.NewGenesisState(
|
||||
evmtypes.NewParams(
|
||||
chaincfg.BaseDenom, // evmDenom
|
||||
"neuron", // evmDenom
|
||||
false, // allowedUnprotectedTxs
|
||||
true, // enableCreate
|
||||
true, // enableCall
|
||||
@ -266,10 +266,10 @@ func (suite *EIP712TestSuite) SetupTest() {
|
||||
pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pricefeedGenState),
|
||||
}
|
||||
|
||||
// funds our test accounts with some a0gi
|
||||
// funds our test accounts with some ua0gi
|
||||
coinsGenState := app.NewFundedGenStateWithSameCoins(
|
||||
tApp.AppCodec(),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1e3)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 1e9)),
|
||||
[]sdk.AccAddress{suite.testAddr, suite.testAddr2},
|
||||
)
|
||||
|
||||
@ -464,7 +464,7 @@ func (suite *EIP712TestSuite) deployUSDCERC20(app app.TestApp, ctx sdk.Context)
|
||||
suite.tApp.FundModuleAccount(
|
||||
suite.ctx,
|
||||
evmutiltypes.ModuleName,
|
||||
sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(0))),
|
||||
sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(0))),
|
||||
)
|
||||
|
||||
contractAddr, err := suite.evmutilKeeper.DeployTestMintableERC20Contract(suite.ctx, "USDC", "USDC", uint8(18))
|
||||
@ -561,7 +561,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
||||
errMsg: "insufficient funds",
|
||||
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
||||
bk := suite.tApp.GetBankKeeper()
|
||||
gasCoins := bk.GetBalance(suite.ctx, suite.testAddr, chaincfg.DisplayDenom)
|
||||
gasCoins := bk.GetBalance(suite.ctx, suite.testAddr, "ua0gi")
|
||||
suite.tApp.GetBankKeeper().SendCoins(suite.ctx, suite.testAddr, suite.testAddr2, sdk.NewCoins(gasCoins))
|
||||
return txBuilder
|
||||
},
|
||||
@ -573,7 +573,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
||||
failCheckTx: true,
|
||||
errMsg: "invalid chain-id",
|
||||
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20)))
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(20)))
|
||||
return suite.createTestEIP712CosmosTxBuilder(
|
||||
suite.testAddr, suite.testPrivKey, "kavatest_12-1", uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||
)
|
||||
@ -586,7 +586,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
||||
failCheckTx: true,
|
||||
errMsg: "invalid pubkey",
|
||||
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20)))
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(20)))
|
||||
return suite.createTestEIP712CosmosTxBuilder(
|
||||
suite.testAddr2, suite.testPrivKey2, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||
)
|
||||
@ -626,7 +626,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
||||
msgs = tc.updateMsgs(msgs)
|
||||
}
|
||||
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20)))
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(20)))
|
||||
txBuilder := suite.createTestEIP712CosmosTxBuilder(
|
||||
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||
)
|
||||
@ -712,7 +712,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx_DepositAndWithdraw() {
|
||||
}
|
||||
|
||||
// deliver deposit msg
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20)))
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(20)))
|
||||
txBuilder := suite.createTestEIP712CosmosTxBuilder(
|
||||
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, depositMsgs,
|
||||
)
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/app/ante"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
)
|
||||
|
||||
func mustParseDecCoins(value string) sdk.DecCoins {
|
||||
@ -31,7 +30,7 @@ func TestEvmMinGasFilter(t *testing.T) {
|
||||
|
||||
ctx := tApp.NewContext(true, tmproto.Header{Height: 1, Time: tmtime.Now()})
|
||||
tApp.GetEvmKeeper().SetParams(ctx, evmtypes.Params{
|
||||
EvmDenom: chaincfg.BaseDenom,
|
||||
EvmDenom: "neuron",
|
||||
})
|
||||
|
||||
testCases := []struct {
|
||||
@ -45,29 +44,29 @@ func TestEvmMinGasFilter(t *testing.T) {
|
||||
mustParseDecCoins(""),
|
||||
},
|
||||
{
|
||||
"zero a0gi gas price",
|
||||
mustParseDecCoins("0a0gi"),
|
||||
mustParseDecCoins("0a0gi"),
|
||||
"zero ua0gi gas price",
|
||||
mustParseDecCoins("0ua0gi"),
|
||||
mustParseDecCoins("0ua0gi"),
|
||||
},
|
||||
{
|
||||
"non-zero a0gi gas price",
|
||||
mustParseDecCoins("0.001a0gi"),
|
||||
mustParseDecCoins("0.001a0gi"),
|
||||
"non-zero ua0gi gas price",
|
||||
mustParseDecCoins("0.001ua0gi"),
|
||||
mustParseDecCoins("0.001ua0gi"),
|
||||
},
|
||||
{
|
||||
"zero a0gi gas price, min neuron price",
|
||||
mustParseDecCoins("0a0gi;100000neuron"),
|
||||
mustParseDecCoins("0a0gi"), // neuron is removed
|
||||
"zero ua0gi gas price, min neuron price",
|
||||
mustParseDecCoins("0ua0gi;100000neuron"),
|
||||
mustParseDecCoins("0ua0gi"), // neuron is removed
|
||||
},
|
||||
{
|
||||
"zero a0gi gas price, min neuron price, other token",
|
||||
mustParseDecCoins("0a0gi;100000neuron;0.001other"),
|
||||
mustParseDecCoins("0a0gi;0.001other"), // neuron is removed
|
||||
"zero ua0gi gas price, min neuron price, other token",
|
||||
mustParseDecCoins("0ua0gi;100000neuron;0.001other"),
|
||||
mustParseDecCoins("0ua0gi;0.001other"), // neuron is removed
|
||||
},
|
||||
{
|
||||
"non-zero a0gi gas price, min neuron price",
|
||||
mustParseDecCoins("0.25a0gi;100000neuron;0.001other"),
|
||||
mustParseDecCoins("0.25a0gi;0.001other"), // neuron is removed
|
||||
"non-zero ua0gi gas price, min neuron price",
|
||||
mustParseDecCoins("0.25ua0gi;100000neuron;0.001other"),
|
||||
mustParseDecCoins("0.25ua0gi;0.001other"), // neuron is removed
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
||||
"MsgCreateVestingAccount",
|
||||
vesting.NewMsgCreateVestingAccount(
|
||||
testAddresses[0], testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100)),
|
||||
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC).Unix(),
|
||||
false,
|
||||
),
|
||||
@ -46,7 +46,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
||||
"MsgCreateVestingAccount",
|
||||
vesting.NewMsgCreatePermanentLockedAccount(
|
||||
testAddresses[0], testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100)),
|
||||
),
|
||||
true,
|
||||
"MsgTypeURL /cosmos.vesting.v1beta1.MsgCreatePermanentLockedAccount not supported",
|
||||
@ -65,7 +65,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
||||
"other messages not affected",
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0], testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100)),
|
||||
),
|
||||
false,
|
||||
"",
|
||||
|
@ -5,8 +5,6 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
|
||||
dbm "github.com/cometbft/cometbft-db"
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
tmjson "github.com/cometbft/cometbft/libs/json"
|
||||
@ -319,9 +317,6 @@ type App struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
// 1stake = 1 ukava = 1_000_000_000_000 akava = 1_000_000_000_000 neuron
|
||||
conversionMultiplier := sdkmath.NewIntFromUint64(1_000_000_000_000)
|
||||
sdk.DefaultPowerReduction = sdk.DefaultPowerReduction.Mul(conversionMultiplier)
|
||||
}
|
||||
|
||||
// NewApp returns a reference to an initialized App.
|
||||
|
@ -169,7 +169,7 @@ func GenesisStateWithSingleValidator(
|
||||
balances := []banktypes.Balance{
|
||||
{
|
||||
Address: acc.GetAddress().String(),
|
||||
Coins: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(100000000000000))),
|
||||
Coins: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(100000000000000))),
|
||||
},
|
||||
}
|
||||
|
||||
@ -232,7 +232,7 @@ func genesisStateWithValSet(
|
||||
}
|
||||
// set validators and delegations
|
||||
currentStakingGenesis := stakingtypes.GetGenesisStateFromAppState(app.appCodec, genesisState)
|
||||
currentStakingGenesis.Params.BondDenom = chaincfg.DisplayDenom
|
||||
currentStakingGenesis.Params.BondDenom = "ua0gi"
|
||||
|
||||
stakingGenesis := stakingtypes.NewGenesisState(
|
||||
currentStakingGenesis.Params,
|
||||
@ -252,13 +252,13 @@ func genesisStateWithValSet(
|
||||
|
||||
for range delegations {
|
||||
// add delegated tokens to total supply
|
||||
totalSupply = totalSupply.Add(sdk.NewCoin(chaincfg.DisplayDenom, bondAmt))
|
||||
totalSupply = totalSupply.Add(sdk.NewCoin("ua0gi", bondAmt))
|
||||
}
|
||||
|
||||
// add bonded amount to bonded pool module account
|
||||
balances = append(balances, banktypes.Balance{
|
||||
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(),
|
||||
Coins: sdk.Coins{sdk.NewCoin(chaincfg.DisplayDenom, bondAmt)},
|
||||
Coins: sdk.Coins{sdk.NewCoin("ua0gi", bondAmt)},
|
||||
})
|
||||
|
||||
bankGenesis := banktypes.NewGenesisState(
|
||||
|
@ -1,27 +0,0 @@
|
||||
package chaincfg
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
const (
|
||||
// DisplayDenom defines the denomination displayed to users in client applications.
|
||||
DisplayDenom = "a0gi"
|
||||
// BaseDenom defines to the default denomination used in 0g-chain
|
||||
BaseDenom = "neuron"
|
||||
|
||||
BaseDenomUnit = 18
|
||||
|
||||
ConversionMultiplier = 1e18
|
||||
)
|
||||
|
||||
// RegisterDenoms registers the base and display denominations to the SDK.
|
||||
func RegisterDenoms() {
|
||||
if err := sdk.RegisterDenom(DisplayDenom, sdk.OneDec()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := sdk.RegisterDenom(BaseDenom, sdk.NewDecWithPrec(1, BaseDenomUnit)); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
@ -10,6 +10,8 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
chaincfg.SetSDKConfig().Seal()
|
||||
|
||||
rootCmd := NewRootCmd()
|
||||
|
||||
if err := svrcmd.Execute(rootCmd, chaincfg.EnvPrefix, chaincfg.DefaultNodeHome); err != nil {
|
||||
|
@ -75,7 +75,7 @@ func NewRootCmd() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
customAppTemplate, customAppConfig := servercfg.AppConfig(chaincfg.BaseDenom)
|
||||
customAppTemplate, customAppConfig := servercfg.AppConfig("ua0gi")
|
||||
|
||||
return server.InterceptConfigsPreRunHandler(
|
||||
cmd,
|
||||
|
@ -4,8 +4,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@ -43,7 +41,7 @@ func TestResetPeriodVestingAccount_NoVestingPeriods(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_SingleVestingPeriod_Vested(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
@ -66,7 +64,7 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_Vested(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_SingleVestingPeriod_Vesting(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
@ -99,7 +97,7 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_Vesting(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_SingleVestingPeriod_ExactStartTime(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
@ -127,25 +125,25 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_ExactStartTime(t *testing
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_MultiplePeriods(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(4)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(4e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // -15 days - vested
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // +30 days - vesting
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
|
||||
},
|
||||
}
|
||||
|
||||
@ -161,36 +159,36 @@ func TestResetPeriodVestingAccount_MultiplePeriods(t *testing.T) {
|
||||
expectedPeriods := []vestingtypes.Period{
|
||||
{
|
||||
Length: 15 * 24 * 60 * 60, // 15 days
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
|
||||
},
|
||||
{
|
||||
Length: 15 * 24 * 60 * 60, // 15 days
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
|
||||
},
|
||||
}
|
||||
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(2))), vacc.OriginalVesting, "expected original vesting to be updated")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(2e6))), vacc.OriginalVesting, "expected original vesting to be updated")
|
||||
assert.Equal(t, newVestingStartTime.Unix(), vacc.StartTime, "expected vesting start time to be updated")
|
||||
assert.Equal(t, expectedEndtime, vacc.EndTime, "expected vesting end time end at last period")
|
||||
assert.Equal(t, expectedPeriods, vacc.VestingPeriods, "expected vesting periods to be updated")
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_DelegatedVesting_GreaterThanVesting(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(3)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(3e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // -15 days - vested
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
|
||||
},
|
||||
}
|
||||
|
||||
@ -200,35 +198,35 @@ func TestResetPeriodVestingAccount_DelegatedVesting_GreaterThanVesting(t *testin
|
||||
newVestingStartTime := vestingStartTime.Add(30 * 24 * time.Hour)
|
||||
ResetPeriodicVestingAccount(vacc, newVestingStartTime)
|
||||
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(2))), vacc.DelegatedFree, "expected delegated free to be updated")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))), vacc.DelegatedVesting, "expected delegated vesting to be updated")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(2e6))), vacc.DelegatedFree, "expected delegated free to be updated")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be updated")
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_DelegatedVesting_LessThanVested(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(3)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(3e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // -15 days - vested
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
|
||||
},
|
||||
}
|
||||
|
||||
vacc := createVestingAccount(balance, vestingStartTime, periods)
|
||||
vacc.TrackDelegation(vestingStartTime, balance, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))))
|
||||
vacc.TrackDelegation(vestingStartTime, balance, sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))))
|
||||
|
||||
newVestingStartTime := vestingStartTime.Add(30 * 24 * time.Hour)
|
||||
ResetPeriodicVestingAccount(vacc, newVestingStartTime)
|
||||
|
||||
assert.Equal(t, sdk.Coins(nil), vacc.DelegatedFree, "expected delegrated free to be unmodified")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1))), vacc.DelegatedVesting, "expected delegated vesting to be unmodified")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be unmodified")
|
||||
}
|
||||
|
@ -9,12 +9,19 @@ import (
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
)
|
||||
|
||||
// ConversionMultiplier is the conversion multiplier between neuron and a0gi
|
||||
var ConversionMultiplier = sdkmath.NewInt(chaincfg.ConversionMultiplier)
|
||||
const (
|
||||
// EvmDenom is the gas denom used by the evm
|
||||
EvmDenom = "neuron"
|
||||
|
||||
// CosmosDenom is the gas denom used by the 0g-chain app
|
||||
CosmosDenom = "ua0gi"
|
||||
)
|
||||
|
||||
// ConversionMultiplier is the conversion multiplier between neuron and ua0gi
|
||||
var ConversionMultiplier = sdkmath.NewInt(1_000_000_000_000)
|
||||
|
||||
var _ evmtypes.BankKeeper = EvmBankKeeper{}
|
||||
|
||||
@ -25,30 +32,30 @@ var _ evmtypes.BankKeeper = EvmBankKeeper{}
|
||||
// This keeper uses both the a0gi coin and a separate neuron balance to manage the
|
||||
// extra percision needed by the evm.
|
||||
type EvmBankKeeper struct {
|
||||
baseKeeper Keeper
|
||||
bk types.BankKeeper
|
||||
ak types.AccountKeeper
|
||||
neuronKeeper Keeper
|
||||
bk types.BankKeeper
|
||||
ak types.AccountKeeper
|
||||
}
|
||||
|
||||
func NewEvmBankKeeper(baseKeeper Keeper, bk types.BankKeeper, ak types.AccountKeeper) EvmBankKeeper {
|
||||
func NewEvmBankKeeper(neuronKeeper Keeper, bk types.BankKeeper, ak types.AccountKeeper) EvmBankKeeper {
|
||||
return EvmBankKeeper{
|
||||
baseKeeper: baseKeeper,
|
||||
bk: bk,
|
||||
ak: ak,
|
||||
neuronKeeper: neuronKeeper,
|
||||
bk: bk,
|
||||
ak: ak,
|
||||
}
|
||||
}
|
||||
|
||||
// GetBalance returns the total **spendable** balance of neuron for a given account by address.
|
||||
func (k EvmBankKeeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin {
|
||||
if denom != chaincfg.BaseDenom {
|
||||
panic(fmt.Errorf("only evm denom %s is supported by EvmBankKeeper", chaincfg.BaseDenom))
|
||||
if denom != EvmDenom {
|
||||
panic(fmt.Errorf("only evm denom %s is supported by EvmBankKeeper", EvmDenom))
|
||||
}
|
||||
|
||||
spendableCoins := k.bk.SpendableCoins(ctx, addr)
|
||||
a0gi := spendableCoins.AmountOf(chaincfg.DisplayDenom)
|
||||
neuron := k.baseKeeper.GetBalance(ctx, addr)
|
||||
total := a0gi.Mul(ConversionMultiplier).Add(neuron)
|
||||
return sdk.NewCoin(chaincfg.BaseDenom, total)
|
||||
ua0gi := spendableCoins.AmountOf(CosmosDenom)
|
||||
neuron := k.neuronKeeper.GetBalance(ctx, addr)
|
||||
total := ua0gi.Mul(ConversionMultiplier).Add(neuron)
|
||||
return sdk.NewCoin(EvmDenom, total)
|
||||
}
|
||||
|
||||
// SendCoins transfers neuron coins from a AccAddress to an AccAddress.
|
||||
@ -63,97 +70,97 @@ func (k EvmBankKeeper) SendCoins(ctx sdk.Context, senderAddr sdk.AccAddress, rec
|
||||
// It will panic if the module account does not exist. An error is returned if the recipient
|
||||
// address is black-listed or if sending the tokens fails.
|
||||
func (k EvmBankKeeper) SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error {
|
||||
a0gi, neuron, err := SplitNeuronCoins(amt)
|
||||
ua0gi, neuron, err := SplitNeuronCoins(amt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if a0gi.Amount.IsPositive() {
|
||||
if err := k.bk.SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, sdk.NewCoins(a0gi)); err != nil {
|
||||
if ua0gi.Amount.IsPositive() {
|
||||
if err := k.bk.SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, sdk.NewCoins(ua0gi)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
senderAddr := k.GetModuleAddress(senderModule)
|
||||
if err := k.ConvertOneA0giToNeuronIfNeeded(ctx, senderAddr, neuron); err != nil {
|
||||
if err := k.ConvertOneUa0giToNeuronIfNeeded(ctx, senderAddr, neuron); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := k.baseKeeper.SendBalance(ctx, senderAddr, recipientAddr, neuron); err != nil {
|
||||
if err := k.neuronKeeper.SendBalance(ctx, senderAddr, recipientAddr, neuron); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return k.ConvertNeuronToA0gi(ctx, recipientAddr)
|
||||
return k.ConvertNeuronToUa0gi(ctx, recipientAddr)
|
||||
}
|
||||
|
||||
// SendCoinsFromAccountToModule transfers neuron coins from an AccAddress to a ModuleAccount.
|
||||
// It will panic if the module account does not exist.
|
||||
func (k EvmBankKeeper) SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error {
|
||||
a0gi, neuronNeeded, err := SplitNeuronCoins(amt)
|
||||
ua0gi, neuronNeeded, err := SplitNeuronCoins(amt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if a0gi.IsPositive() {
|
||||
if err := k.bk.SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, sdk.NewCoins(a0gi)); err != nil {
|
||||
if ua0gi.IsPositive() {
|
||||
if err := k.bk.SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, sdk.NewCoins(ua0gi)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := k.ConvertOneA0giToNeuronIfNeeded(ctx, senderAddr, neuronNeeded); err != nil {
|
||||
if err := k.ConvertOneUa0giToNeuronIfNeeded(ctx, senderAddr, neuronNeeded); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
recipientAddr := k.GetModuleAddress(recipientModule)
|
||||
if err := k.baseKeeper.SendBalance(ctx, senderAddr, recipientAddr, neuronNeeded); err != nil {
|
||||
if err := k.neuronKeeper.SendBalance(ctx, senderAddr, recipientAddr, neuronNeeded); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return k.ConvertNeuronToA0gi(ctx, recipientAddr)
|
||||
return k.ConvertNeuronToUa0gi(ctx, recipientAddr)
|
||||
}
|
||||
|
||||
// MintCoins mints neuron coins by minting the equivalent a0gi coins and any remaining neuron coins.
|
||||
// It will panic if the module account does not exist or is unauthorized.
|
||||
func (k EvmBankKeeper) MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error {
|
||||
a0gi, neuron, err := SplitNeuronCoins(amt)
|
||||
ua0gi, neuron, err := SplitNeuronCoins(amt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if a0gi.IsPositive() {
|
||||
if err := k.bk.MintCoins(ctx, moduleName, sdk.NewCoins(a0gi)); err != nil {
|
||||
if ua0gi.IsPositive() {
|
||||
if err := k.bk.MintCoins(ctx, moduleName, sdk.NewCoins(ua0gi)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
recipientAddr := k.GetModuleAddress(moduleName)
|
||||
if err := k.baseKeeper.AddBalance(ctx, recipientAddr, neuron); err != nil {
|
||||
if err := k.neuronKeeper.AddBalance(ctx, recipientAddr, neuron); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return k.ConvertNeuronToA0gi(ctx, recipientAddr)
|
||||
return k.ConvertNeuronToUa0gi(ctx, recipientAddr)
|
||||
}
|
||||
|
||||
// BurnCoins burns neuron coins by burning the equivalent a0gi coins and any remaining neuron coins.
|
||||
// It will panic if the module account does not exist or is unauthorized.
|
||||
func (k EvmBankKeeper) BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error {
|
||||
a0gi, neuron, err := SplitNeuronCoins(amt)
|
||||
ua0gi, neuron, err := SplitNeuronCoins(amt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if a0gi.IsPositive() {
|
||||
if err := k.bk.BurnCoins(ctx, moduleName, sdk.NewCoins(a0gi)); err != nil {
|
||||
if ua0gi.IsPositive() {
|
||||
if err := k.bk.BurnCoins(ctx, moduleName, sdk.NewCoins(ua0gi)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
moduleAddr := k.GetModuleAddress(moduleName)
|
||||
if err := k.ConvertOneA0giToNeuronIfNeeded(ctx, moduleAddr, neuron); err != nil {
|
||||
if err := k.ConvertOneUa0giToNeuronIfNeeded(ctx, moduleAddr, neuron); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return k.baseKeeper.RemoveBalance(ctx, moduleAddr, neuron)
|
||||
return k.neuronKeeper.RemoveBalance(ctx, moduleAddr, neuron)
|
||||
}
|
||||
|
||||
// IsSendEnabledCoins checks the coins provided and returns an ErrSendDisabled
|
||||
@ -168,20 +175,20 @@ func (k EvmBankKeeper) IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) er
|
||||
|
||||
// ConvertOneA0giToNeuronIfNeeded converts 1 a0gi to neuron for an address if
|
||||
// its neuron balance is smaller than the neuronNeeded amount.
|
||||
func (k EvmBankKeeper) ConvertOneA0giToNeuronIfNeeded(ctx sdk.Context, addr sdk.AccAddress, neuronNeeded sdkmath.Int) error {
|
||||
neuronBal := k.baseKeeper.GetBalance(ctx, addr)
|
||||
func (k EvmBankKeeper) ConvertOneUa0giToNeuronIfNeeded(ctx sdk.Context, addr sdk.AccAddress, neuronNeeded sdkmath.Int) error {
|
||||
neuronBal := k.neuronKeeper.GetBalance(ctx, addr)
|
||||
if neuronBal.GTE(neuronNeeded) {
|
||||
return nil
|
||||
}
|
||||
|
||||
a0giToStore := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdk.OneInt()))
|
||||
if err := k.bk.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, a0giToStore); err != nil {
|
||||
ua0giToStore := sdk.NewCoins(sdk.NewCoin(CosmosDenom, sdk.OneInt()))
|
||||
if err := k.bk.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, ua0giToStore); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add 1a0gi equivalent of neuron to addr
|
||||
neuronToReceive := ConversionMultiplier
|
||||
if err := k.baseKeeper.AddBalance(ctx, addr, neuronToReceive); err != nil {
|
||||
if err := k.neuronKeeper.AddBalance(ctx, addr, neuronToReceive); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -189,28 +196,28 @@ func (k EvmBankKeeper) ConvertOneA0giToNeuronIfNeeded(ctx sdk.Context, addr sdk.
|
||||
}
|
||||
|
||||
// ConvertNeuronToA0gi converts all available neuron to a0gi for a given AccAddress.
|
||||
func (k EvmBankKeeper) ConvertNeuronToA0gi(ctx sdk.Context, addr sdk.AccAddress) error {
|
||||
totalNeuron := k.baseKeeper.GetBalance(ctx, addr)
|
||||
a0gi, _, err := SplitNeuronCoins(sdk.NewCoins(sdk.NewCoin(chaincfg.BaseDenom, totalNeuron)))
|
||||
func (k EvmBankKeeper) ConvertNeuronToUa0gi(ctx sdk.Context, addr sdk.AccAddress) error {
|
||||
totalNeuron := k.neuronKeeper.GetBalance(ctx, addr)
|
||||
ua0gi, _, err := SplitNeuronCoins(sdk.NewCoins(sdk.NewCoin(EvmDenom, totalNeuron)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// do nothing if account does not have enough neuron for a single a0gi
|
||||
a0giToReceive := a0gi.Amount
|
||||
if !a0giToReceive.IsPositive() {
|
||||
ua0giToReceive := ua0gi.Amount
|
||||
if !ua0giToReceive.IsPositive() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// remove neuron used for converting to a0gi
|
||||
neuronToBurn := a0giToReceive.Mul(ConversionMultiplier)
|
||||
// remove neuron used for converting to ua0gi
|
||||
neuronToBurn := ua0giToReceive.Mul(ConversionMultiplier)
|
||||
finalBal := totalNeuron.Sub(neuronToBurn)
|
||||
if err := k.baseKeeper.SetBalance(ctx, addr, finalBal); err != nil {
|
||||
if err := k.neuronKeeper.SetBalance(ctx, addr, finalBal); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fromAddr := k.GetModuleAddress(types.ModuleName)
|
||||
if err := k.bk.SendCoins(ctx, fromAddr, addr, sdk.NewCoins(a0gi)); err != nil {
|
||||
if err := k.bk.SendCoins(ctx, fromAddr, addr, sdk.NewCoins(ua0gi)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -229,14 +236,14 @@ func (k EvmBankKeeper) GetModuleAddress(moduleName string) sdk.AccAddress {
|
||||
// An error will be returned if the coins are not valid or if the coins are not the neuron denom.
|
||||
func SplitNeuronCoins(coins sdk.Coins) (sdk.Coin, sdkmath.Int, error) {
|
||||
neuron := sdk.ZeroInt()
|
||||
a0gi := sdk.NewCoin(chaincfg.DisplayDenom, sdk.ZeroInt())
|
||||
ua0gi := sdk.NewCoin(CosmosDenom, sdk.ZeroInt())
|
||||
|
||||
if len(coins) == 0 {
|
||||
return a0gi, neuron, nil
|
||||
return ua0gi, neuron, nil
|
||||
}
|
||||
|
||||
if err := ValidateEvmCoins(coins); err != nil {
|
||||
return a0gi, neuron, err
|
||||
return ua0gi, neuron, err
|
||||
}
|
||||
|
||||
// note: we should always have len(coins) == 1 here since coins cannot have dup denoms after we validate.
|
||||
@ -245,15 +252,15 @@ func SplitNeuronCoins(coins sdk.Coins) (sdk.Coin, sdkmath.Int, error) {
|
||||
if remainingBalance.IsPositive() {
|
||||
neuron = remainingBalance
|
||||
}
|
||||
a0giAmount := coin.Amount.Quo(ConversionMultiplier)
|
||||
if a0giAmount.IsPositive() {
|
||||
a0gi = sdk.NewCoin(chaincfg.DisplayDenom, a0giAmount)
|
||||
ua0giAmount := coin.Amount.Quo(ConversionMultiplier)
|
||||
if ua0giAmount.IsPositive() {
|
||||
ua0gi = sdk.NewCoin(CosmosDenom, ua0giAmount)
|
||||
}
|
||||
|
||||
return a0gi, neuron, nil
|
||||
return ua0gi, neuron, nil
|
||||
}
|
||||
|
||||
// ValidateEvmCoins validates the coins from evm is valid and is the chaincfg.BaseDenom (neuron).
|
||||
// ValidateEvmCoins validates the coins from evm is valid and is the EvmDenom (neuron).
|
||||
func ValidateEvmCoins(coins sdk.Coins) error {
|
||||
if len(coins) == 0 {
|
||||
return nil
|
||||
@ -265,8 +272,8 @@ func ValidateEvmCoins(coins sdk.Coins) error {
|
||||
}
|
||||
|
||||
// validate that coin denom is neuron
|
||||
if len(coins) != 1 || coins[0].Denom != chaincfg.BaseDenom {
|
||||
errMsg := fmt.Sprintf("invalid evm coin denom, only %s is supported", chaincfg.BaseDenom)
|
||||
if len(coins) != 1 || coins[0].Denom != EvmDenom {
|
||||
errMsg := fmt.Sprintf("invalid evm coin denom, only %s is supported", EvmDenom)
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, errMsg)
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
)
|
||||
|
||||
@ -51,7 +50,7 @@ func FullyBackedInvariant(bankK types.BankKeeper, k Keeper) sdk.Invariant {
|
||||
})
|
||||
|
||||
bankAddr := authtypes.NewModuleAddress(types.ModuleName)
|
||||
bankBalance := bankK.GetBalance(ctx, bankAddr, chaincfg.DisplayDenom).Amount.Mul(ConversionMultiplier)
|
||||
bankBalance := bankK.GetBalance(ctx, bankAddr, CosmosDenom).Amount.Mul(ConversionMultiplier)
|
||||
|
||||
broken = totalMinorBalances.GT(bankBalance)
|
||||
|
||||
|
@ -50,7 +50,7 @@ func (suite *invariantTestSuite) SetupValidState() {
|
||||
suite.FundModuleAccountWithZgChain(
|
||||
types.ModuleName,
|
||||
sdk.NewCoins(
|
||||
sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(2)), // ( sum of all minor balances ) / conversion multiplier
|
||||
sdk.NewCoin("ua0gi", sdkmath.NewInt(2)), // ( sum of all minor balances ) / conversion multiplier
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -82,14 +82,14 @@ func (suite *Suite) SetupTest() {
|
||||
suite.Addrs = addrs
|
||||
|
||||
evmGenesis := evmtypes.DefaultGenesisState()
|
||||
evmGenesis.Params.EvmDenom = chaincfg.BaseDenom
|
||||
evmGenesis.Params.EvmDenom = chaincfg.EvmDenom
|
||||
|
||||
feemarketGenesis := feemarkettypes.DefaultGenesisState()
|
||||
feemarketGenesis.Params.EnableHeight = 1
|
||||
feemarketGenesis.Params.NoBaseFee = false
|
||||
|
||||
cdc := suite.App.AppCodec()
|
||||
coins := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1000_000_000_000))
|
||||
coins := sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 1000_000_000_000))
|
||||
authGS := app.NewFundedGenStateWithSameCoins(cdc, coins, []sdk.AccAddress{
|
||||
sdk.AccAddress(suite.Key1.PubKey().Address()),
|
||||
sdk.AccAddress(suite.Key2.PubKey().Address()),
|
||||
@ -186,12 +186,12 @@ func (suite *Suite) ModuleBalance(denom string) sdk.Int {
|
||||
}
|
||||
|
||||
func (suite *Suite) FundAccountWithZgChain(addr sdk.AccAddress, coins sdk.Coins) {
|
||||
a0gi := coins.AmountOf(chaincfg.DisplayDenom)
|
||||
if a0gi.IsPositive() {
|
||||
err := suite.App.FundAccount(suite.Ctx, addr, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, a0gi)))
|
||||
ua0gi := coins.AmountOf("ua0gi")
|
||||
if ua0gi.IsPositive() {
|
||||
err := suite.App.FundAccount(suite.Ctx, addr, sdk.NewCoins(sdk.NewCoin("ua0gi", ua0gi)))
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
neuron := coins.AmountOf(chaincfg.BaseDenom)
|
||||
neuron := coins.AmountOf("neuron")
|
||||
if neuron.IsPositive() {
|
||||
err := suite.Keeper.SetBalance(suite.Ctx, addr, neuron)
|
||||
suite.Require().NoError(err)
|
||||
@ -199,12 +199,12 @@ func (suite *Suite) FundAccountWithZgChain(addr sdk.AccAddress, coins sdk.Coins)
|
||||
}
|
||||
|
||||
func (suite *Suite) FundModuleAccountWithZgChain(moduleName string, coins sdk.Coins) {
|
||||
a0gi := coins.AmountOf(chaincfg.DisplayDenom)
|
||||
if a0gi.IsPositive() {
|
||||
err := suite.App.FundModuleAccount(suite.Ctx, moduleName, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, a0gi)))
|
||||
ua0gi := coins.AmountOf("ua0gi")
|
||||
if ua0gi.IsPositive() {
|
||||
err := suite.App.FundModuleAccount(suite.Ctx, moduleName, sdk.NewCoins(sdk.NewCoin("ua0gi", ua0gi)))
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
neuron := coins.AmountOf(chaincfg.BaseDenom)
|
||||
neuron := coins.AmountOf("neuron")
|
||||
if neuron.IsPositive() {
|
||||
addr := suite.AccountKeeper.GetModuleAddress(moduleName)
|
||||
err := suite.Keeper.SetBalance(suite.Ctx, addr, neuron)
|
||||
@ -218,7 +218,7 @@ func (suite *Suite) DeployERC20() types.InternalEVMAddress {
|
||||
suite.App.FundModuleAccount(
|
||||
suite.Ctx,
|
||||
types.ModuleName,
|
||||
sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(0))),
|
||||
sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(0))),
|
||||
)
|
||||
|
||||
contractAddr, err := suite.Keeper.DeployTestMintableERC20Contract(suite.Ctx, "USDC", "USDC", uint8(18))
|
||||
@ -319,7 +319,7 @@ func (suite *Suite) SendTx(
|
||||
// Mint the max gas to the FeeCollector to ensure balance in case of refund
|
||||
suite.MintFeeCollector(sdk.NewCoins(
|
||||
sdk.NewCoin(
|
||||
chaincfg.DisplayDenom,
|
||||
"ua0gi",
|
||||
sdkmath.NewInt(baseFee.Int64()*int64(gasRes.Gas*2)),
|
||||
)))
|
||||
|
||||
|
@ -63,7 +63,7 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
|
||||
},
|
||||
"supplies": [
|
||||
{
|
||||
"current_supply": { "denom": "neuron", "amount": "100000000000000" },
|
||||
"current_supply": { "denom": "ua0gi", "amount": "100" },
|
||||
"time_elapsed": "3600000000000"
|
||||
},
|
||||
{
|
||||
@ -96,7 +96,7 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
|
||||
},
|
||||
"supplies": [
|
||||
{
|
||||
"current_supply": { "denom": "neuron", "amount": "100000000000000" },
|
||||
"current_supply": { "denom": "ua0gi", "amount": "100" },
|
||||
"time_elapsed": "3600s"
|
||||
},
|
||||
{
|
||||
@ -115,7 +115,7 @@ func (s *migrateTestSuite) TestMigrate_Params() {
|
||||
Assets: v015issuance.Assets{
|
||||
{
|
||||
Owner: s.addresses[0],
|
||||
Denom: "neuron",
|
||||
Denom: "ua0gi",
|
||||
BlockedAddresses: s.addresses[1:2],
|
||||
Paused: true,
|
||||
Blockable: true,
|
||||
@ -131,7 +131,7 @@ func (s *migrateTestSuite) TestMigrate_Params() {
|
||||
Assets: []v016issuance.Asset{
|
||||
{
|
||||
Owner: s.addresses[0].String(),
|
||||
Denom: "neuron",
|
||||
Denom: "ua0gi",
|
||||
BlockedAddresses: []string{s.addresses[1].String()},
|
||||
Paused: true,
|
||||
Blockable: true,
|
||||
@ -150,7 +150,7 @@ func (s *migrateTestSuite) TestMigrate_Params() {
|
||||
func (s *migrateTestSuite) TestMigrate_Supplies() {
|
||||
s.v15genstate.Supplies = v015issuance.AssetSupplies{
|
||||
{
|
||||
CurrentSupply: sdk.NewCoin("neuron", sdkmath.NewInt(100000000000000)),
|
||||
CurrentSupply: sdk.NewCoin("ua0gi", sdkmath.NewInt(100)),
|
||||
TimeElapsed: time.Duration(1 * time.Hour),
|
||||
},
|
||||
{
|
||||
@ -160,7 +160,7 @@ func (s *migrateTestSuite) TestMigrate_Supplies() {
|
||||
}
|
||||
expected := []v016issuance.AssetSupply{
|
||||
{
|
||||
CurrentSupply: sdk.NewCoin("neuron", sdkmath.NewInt(100000000000000)),
|
||||
CurrentSupply: sdk.NewCoin("ua0gi", sdkmath.NewInt(100)),
|
||||
TimeElapsed: time.Duration(1 * time.Hour),
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user