mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
SWP airdrop for USDX suppliers to hard (#996)
* implement swp airdrop to usdx depositors to hard * verify swp airdrop amount, total supply, affected users * remove unused test code * add map as go file * update tests to use stored variable * re-add snapshot test * update snapshot testdata * remove unused code for generating swp airdrop map * remove snapshot test
This commit is contained in:
parent
63508d79f9
commit
61b7f8f56e
87768
migrate/v0_15/data/hard-deposits-block-1543671.json
Normal file
87768
migrate/v0_15/data/hard-deposits-block-1543671.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -71,7 +71,7 @@ func MigrateAppState(v0_14AppState genutil.AppMap) {
|
||||
var authGenState auth.GenesisState
|
||||
v0_14Codec.MustUnmarshalJSON(v0_14AppState[auth.ModuleName], &authGenState)
|
||||
delete(v0_14AppState, auth.ModuleName)
|
||||
v0_14AppState[auth.ModuleName] = v0_15Codec.MustMarshalJSON(Auth(authGenState, GenesisTime))
|
||||
v0_14AppState[auth.ModuleName] = v0_15Codec.MustMarshalJSON(Auth(v0_15Codec, authGenState, GenesisTime))
|
||||
}
|
||||
|
||||
// Migrate incentive app state
|
||||
@ -109,14 +109,35 @@ func makeV014Codec() *codec.Codec {
|
||||
}
|
||||
|
||||
// Auth migrates the auth genesis state to a new state with pruned vesting periods
|
||||
func Auth(genesisState auth.GenesisState, genesisTime time.Time) auth.GenesisState {
|
||||
func Auth(cdc *codec.Codec, genesisState auth.GenesisState, genesisTime time.Time) auth.GenesisState {
|
||||
genesisStateWithAccountsMigrated := MigrateAccounts(genesisState, genesisTime)
|
||||
genesisStateWithSwpAirdrop := ApplySwpAirdrop(cdc, genesisStateWithAccountsMigrated)
|
||||
|
||||
return genesisStateWithSwpAirdrop
|
||||
}
|
||||
|
||||
func ApplySwpAirdrop(cdc *codec.Codec, genesisState auth.GenesisState) auth.GenesisState {
|
||||
accounts := make([]authexported.GenesisAccount, len(genesisState.Accounts))
|
||||
migratedGenesisState := auth.NewGenesisState(genesisState.Params, accounts)
|
||||
|
||||
var swpAirdrop map[string]sdk.Coin
|
||||
cdc.MustUnmarshalJSON([]byte(swpAirdropMap), &swpAirdrop)
|
||||
for i, acc := range genesisState.Accounts {
|
||||
accounts[i] = authexported.GenesisAccount(MigrateAccount(acc, genesisTime))
|
||||
if swpReward, ok := swpAirdrop[acc.GetAddress().String()]; ok {
|
||||
acc.SetCoins(acc.GetCoins().Add(swpReward))
|
||||
}
|
||||
accounts[i] = authexported.GenesisAccount(acc)
|
||||
}
|
||||
return migratedGenesisState
|
||||
}
|
||||
|
||||
func MigrateAccounts(genesisState auth.GenesisState, genesisTime time.Time) auth.GenesisState {
|
||||
accounts := make([]authexported.GenesisAccount, len(genesisState.Accounts))
|
||||
migratedGenesisState := auth.NewGenesisState(genesisState.Params, accounts)
|
||||
for i, acc := range genesisState.Accounts {
|
||||
migratedAcc := MigrateAccount(acc, genesisTime)
|
||||
|
||||
accounts[i] = authexported.GenesisAccount(migratedAcc)
|
||||
}
|
||||
return migratedGenesisState
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package v0_15
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -19,6 +20,7 @@ import (
|
||||
"github.com/kava-labs/kava/app"
|
||||
v0_14committee "github.com/kava-labs/kava/x/committee/legacy/v0_14"
|
||||
v0_15committee "github.com/kava-labs/kava/x/committee/types"
|
||||
"github.com/kava-labs/kava/x/hard"
|
||||
v0_14incentive "github.com/kava-labs/kava/x/incentive/legacy/v0_14"
|
||||
v0_15incentive "github.com/kava-labs/kava/x/incentive/types"
|
||||
)
|
||||
@ -61,13 +63,6 @@ func TestCommittee(t *testing.T) {
|
||||
require.Equal(t, len(oldSPCP.AllowedMarkets), len(newSPCP.AllowedMarkets))
|
||||
require.Equal(t, len(oldSPCP.AllowedMoneyMarkets), len(newSPCP.AllowedMoneyMarkets))
|
||||
}
|
||||
|
||||
// exportGenesisJSON is a utility testing method
|
||||
func exportGenesisJSON(genState v0_15committee.GenesisState) {
|
||||
v15Cdc := app.MakeCodec()
|
||||
ioutil.WriteFile(filepath.Join("testdata", "kava-8-committee-state.json"), v15Cdc.MustMarshalJSON(genState), 0644)
|
||||
}
|
||||
|
||||
func TestIncentive_MainnetState(t *testing.T) {
|
||||
// TODO add copy of mainnet state to json
|
||||
bz, err := ioutil.ReadFile(filepath.Join("testdata", "kava-7-incentive-state.json"))
|
||||
@ -113,25 +108,6 @@ func TestSwap(t *testing.T) {
|
||||
require.Equal(t, 0, len(swapGS.ShareRecords))
|
||||
}
|
||||
|
||||
// Compare migration against auto-generated snapshot to catch regressions
|
||||
func TestAuth_Snapshot(t *testing.T) {
|
||||
bz, err := ioutil.ReadFile(filepath.Join("testdata", "kava-7-test-auth-state.json"))
|
||||
require.NoError(t, err)
|
||||
appState := genutil.AppMap{auth.ModuleName: bz}
|
||||
|
||||
MigrateAppState(appState)
|
||||
|
||||
if _, err := os.Stat(filepath.Join("testdata", "kava-8-test-auth-state.json")); os.IsNotExist(err) {
|
||||
err := ioutil.WriteFile(filepath.Join("testdata", "kava-8-test-auth-state.json"), appState[auth.ModuleName], 0644)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
snapshot, err := ioutil.ReadFile(filepath.Join("testdata", "kava-8-test-auth-state.json"))
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.JSONEq(t, string(snapshot), string(appState[auth.ModuleName]), "expected auth state snapshot to be equal")
|
||||
}
|
||||
|
||||
func TestAuth_ParametersEqual(t *testing.T) {
|
||||
bz, err := ioutil.ReadFile(filepath.Join("testdata", "kava-7-test-auth-state.json"))
|
||||
require.NoError(t, err)
|
||||
@ -140,7 +116,7 @@ func TestAuth_ParametersEqual(t *testing.T) {
|
||||
cdc := app.MakeCodec()
|
||||
cdc.MustUnmarshalJSON(bz, &genesisState)
|
||||
|
||||
migratedGenesisState := Auth(genesisState, GenesisTime)
|
||||
migratedGenesisState := Auth(cdc, genesisState, GenesisTime)
|
||||
|
||||
assert.Equal(t, genesisState.Params, migratedGenesisState.Params, "expected auth parameters to not change")
|
||||
}
|
||||
@ -154,10 +130,9 @@ func TestAuth_AccountConversion(t *testing.T) {
|
||||
var genesisState auth.GenesisState
|
||||
cdc.MustUnmarshalJSON(bz, &genesisState)
|
||||
|
||||
migratedGenesisState := MigrateAccounts(genesisState, GenesisTime)
|
||||
var originalGenesisState auth.GenesisState
|
||||
cdc.MustUnmarshalJSON(bz, &originalGenesisState)
|
||||
|
||||
migratedGenesisState := Auth(genesisState, GenesisTime)
|
||||
require.Equal(t, len(genesisState.Accounts), len(migratedGenesisState.Accounts), "expected the number of accounts after migration to be equal")
|
||||
err = auth.ValidateGenesis(migratedGenesisState)
|
||||
require.NoError(t, err, "expected migrated genesis to be valid")
|
||||
@ -213,3 +188,62 @@ func TestAuth_AccountConversion(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuth_MakeAirdropMap(t *testing.T) {
|
||||
cdc := app.MakeCodec()
|
||||
aidropTokenAmount := sdk.NewInt(1000000000000)
|
||||
totalSwpTokens := sdk.ZeroInt()
|
||||
var loadedAirdropMap map[string]sdk.Coin
|
||||
cdc.MustUnmarshalJSON([]byte(swpAirdropMap), &loadedAirdropMap)
|
||||
for _, coin := range loadedAirdropMap {
|
||||
totalSwpTokens = totalSwpTokens.Add(coin.Amount)
|
||||
}
|
||||
require.Equal(t, aidropTokenAmount, totalSwpTokens)
|
||||
}
|
||||
|
||||
func TestAuth_TestAllDepositorsIncluded(t *testing.T) {
|
||||
var deposits hard.Deposits
|
||||
cdc := app.MakeCodec()
|
||||
bz, err := ioutil.ReadFile("./data/hard-deposits-block-1543671.json")
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Couldn't open hard deposit snapshot file: %v", err))
|
||||
}
|
||||
cdc.MustUnmarshalJSON(bz, &deposits)
|
||||
|
||||
depositorsInSnapShot := 0
|
||||
for _, dep := range deposits {
|
||||
if dep.Amount.AmountOf("usdx").IsPositive() {
|
||||
depositorsInSnapShot++
|
||||
}
|
||||
}
|
||||
var loadedAirdropMap map[string]sdk.Coin
|
||||
cdc.MustUnmarshalJSON([]byte(swpAirdropMap), &loadedAirdropMap)
|
||||
keys := make([]string, 0, len(loadedAirdropMap))
|
||||
for k := range loadedAirdropMap {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
require.Equal(t, depositorsInSnapShot, len(keys))
|
||||
}
|
||||
|
||||
func TestAuth_SwpSupply(t *testing.T) {
|
||||
swpSupply := sdk.NewCoin("swp", sdk.ZeroInt())
|
||||
// TODO update when additional swp are added to migration, final supply should be 250M at genesis
|
||||
expectedSwpSupply := sdk.NewCoin("swp", sdk.NewInt(1000000000000))
|
||||
bz, err := ioutil.ReadFile(filepath.Join("testdata", "block-1543671-auth-state.json"))
|
||||
require.NoError(t, err)
|
||||
|
||||
var genesisState auth.GenesisState
|
||||
cdc := app.MakeCodec()
|
||||
cdc.MustUnmarshalJSON(bz, &genesisState)
|
||||
|
||||
migratedGenesisState := Auth(cdc, genesisState, GenesisTime)
|
||||
|
||||
for _, acc := range migratedGenesisState.Accounts {
|
||||
swpAmount := acc.GetCoins().AmountOf("swp")
|
||||
if swpAmount.IsPositive() {
|
||||
swpCoin := sdk.NewCoin("swp", swpAmount)
|
||||
swpSupply = swpSupply.Add(swpCoin)
|
||||
}
|
||||
}
|
||||
require.Equal(t, expectedSwpSupply, swpSupply)
|
||||
}
|
||||
|
5
migrate/v0_15/swp_airdrop.go
Normal file
5
migrate/v0_15/swp_airdrop.go
Normal file
File diff suppressed because one or more lines are too long
1
migrate/v0_15/testdata/block-1543671-auth-state.json
vendored
Normal file
1
migrate/v0_15/testdata/block-1543671-auth-state.json
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user