-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add rewards bucket keeper logic + tests (#3426)
* feat: add rewards bucket keeper logic + tests * fix: remove unecessary comments * fix: add missing rest endpoints * test: fix linter
- Loading branch information
Showing
30 changed files
with
2,690 additions
and
197 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
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,17 @@ | ||
syntax = "proto3"; | ||
package sifnode.clp.v1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
|
||
option go_package = "github.com/Sifchain/sifnode/x/clp/types"; | ||
|
||
message RewardsBucket { | ||
string denom = 1; | ||
string amount = 2 [ | ||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", | ||
(gogoproto.nullable) = false, | ||
(gogoproto.moretags) = "yaml:\"amount\"" | ||
]; | ||
|
||
} | ||
|
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,59 @@ | ||
package keeper | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/Sifchain/sifnode/x/clp/keeper" | ||
"github.com/Sifchain/sifnode/x/clp/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
"github.com/cosmos/cosmos-sdk/store" | ||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" | ||
typesparams "github.com/cosmos/cosmos-sdk/x/params/types" | ||
"github.com/stretchr/testify/require" | ||
"github.com/tendermint/tendermint/libs/log" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
tmdb "github.com/tendermint/tm-db" | ||
) | ||
|
||
func ClpKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { | ||
storeKey := sdk.NewKVStoreKey(types.StoreKey) | ||
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) | ||
|
||
db := tmdb.NewMemDB() | ||
stateStore := store.NewCommitMultiStore(db) | ||
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) | ||
stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) | ||
require.NoError(t, stateStore.LoadLatestVersion()) | ||
|
||
registry := codectypes.NewInterfaceRegistry() | ||
cdc := codec.NewProtoCodec(registry) | ||
|
||
paramsSubspace := typesparams.NewSubspace(cdc, | ||
types.Amino, | ||
storeKey, | ||
memStoreKey, | ||
"ClpParams", | ||
) | ||
k := keeper.NewKeeper( | ||
cdc, | ||
storeKey, | ||
nil, | ||
nil, | ||
nil, | ||
nil, | ||
mintkeeper.Keeper{}, | ||
nil, | ||
paramsSubspace, | ||
) | ||
|
||
ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) | ||
|
||
// Initialize params | ||
k.SetParams(ctx, types.DefaultParams()) | ||
|
||
return &k, ctx | ||
} |
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 network | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
"github.com/cosmos/cosmos-sdk/crypto/hd" | ||
"github.com/cosmos/cosmos-sdk/crypto/keyring" | ||
servertypes "github.com/cosmos/cosmos-sdk/server/types" | ||
tmdb "github.com/tendermint/tm-db" | ||
|
||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
"github.com/cosmos/cosmos-sdk/testutil/network" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
"github.com/stretchr/testify/require" | ||
tmrand "github.com/tendermint/tendermint/libs/rand" | ||
|
||
"github.com/Sifchain/sifnode/app" | ||
) | ||
|
||
type ( | ||
Network = network.Network | ||
Config = network.Config | ||
) | ||
|
||
// New creates instance with fully configured cosmos network. | ||
// Accepts optional config, that will be used in place of the DefaultConfig() if provided. | ||
func New(t *testing.T, configs ...Config) *Network { | ||
if len(configs) > 1 { | ||
panic("at most one config should be provided") | ||
} | ||
var cfg network.Config | ||
if len(configs) == 0 { | ||
cfg = DefaultConfig() | ||
} else { | ||
cfg = configs[0] | ||
} | ||
net := network.New(t, cfg) | ||
_, err := net.WaitForHeight(1) | ||
require.NoError(t, err) | ||
t.Cleanup(net.Cleanup) | ||
return net | ||
} | ||
|
||
// DefaultConfig will initialize config for the network with custom application, | ||
// genesis and single validator. All other parameters are inherited from cosmos-sdk/testutil/network.DefaultConfig | ||
func DefaultConfig() network.Config { | ||
var ( | ||
encoding = app.MakeTestEncodingConfig() | ||
chainID = "chain-" + tmrand.NewRand().Str(6) | ||
) | ||
return network.Config{ | ||
Codec: encoding.Marshaler, | ||
TxConfig: encoding.TxConfig, | ||
LegacyAmino: encoding.Amino, | ||
InterfaceRegistry: encoding.InterfaceRegistry, | ||
AccountRetriever: authtypes.AccountRetriever{}, | ||
AppConstructor: func(val network.Validator) servertypes.Application { | ||
return app.NewSifApp( | ||
val.Ctx.Logger, | ||
tmdb.NewMemDB(), | ||
nil, | ||
true, | ||
map[int64]bool{}, | ||
val.Ctx.Config.RootDir, | ||
0, | ||
encoding, | ||
app.EmptyAppOptions{}, | ||
baseapp.SetPruning(storetypes.NewPruningOptionsFromString(val.AppConfig.Pruning)), | ||
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices), | ||
) | ||
}, | ||
GenesisState: app.ModuleBasics.DefaultGenesis(encoding.Marshaler), | ||
TimeoutCommit: 2 * time.Second, | ||
ChainID: chainID, | ||
NumValidators: 1, | ||
BondDenom: sdk.DefaultBondDenom, | ||
MinGasPrices: fmt.Sprintf("0.000006%s", sdk.DefaultBondDenom), | ||
AccountTokens: sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction), | ||
StakingTokens: sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction), | ||
BondedTokens: sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction), | ||
PruningStrategy: storetypes.PruningOptionNothing, | ||
CleanupDir: true, | ||
SigningAlgo: string(hd.Secp256k1Type), | ||
KeyringOptions: []keyring.Option{}, | ||
} | ||
} |
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,57 @@ | ||
// Package nullify provides methods to init nil values structs for test assertion. | ||
package nullify | ||
|
||
import ( | ||
"reflect" | ||
"unsafe" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
var ( | ||
coinType = reflect.TypeOf(sdk.Coin{}) | ||
coinsType = reflect.TypeOf(sdk.Coins{}) | ||
) | ||
|
||
// Fill analyze all struct fields and slices with | ||
// reflection and initialize the nil and empty slices, | ||
// structs, and pointers. | ||
func Fill(x interface{}) interface{} { | ||
v := reflect.Indirect(reflect.ValueOf(x)) | ||
switch v.Kind() { | ||
case reflect.Slice: | ||
for i := 0; i < v.Len(); i++ { | ||
obj := v.Index(i) | ||
objPt := reflect.NewAt(obj.Type(), unsafe.Pointer(obj.UnsafeAddr())).Interface() | ||
objPt = Fill(objPt) | ||
obj.Set(reflect.ValueOf(objPt)) | ||
} | ||
case reflect.Struct: | ||
for i := 0; i < v.NumField(); i++ { | ||
f := reflect.Indirect(v.Field(i)) | ||
if !f.CanSet() { | ||
continue | ||
} | ||
switch f.Kind() { | ||
case reflect.Slice: | ||
f.Set(reflect.MakeSlice(f.Type(), 0, 0)) | ||
case reflect.Struct: | ||
switch f.Type() { | ||
case coinType: | ||
coin := reflect.New(coinType).Interface() | ||
s := reflect.ValueOf(coin).Elem() | ||
f.Set(s) | ||
case coinsType: | ||
coins := reflect.New(coinsType).Interface() | ||
s := reflect.ValueOf(coins).Elem() | ||
f.Set(s) | ||
default: | ||
objPt := reflect.NewAt(f.Type(), unsafe.Pointer(f.UnsafeAddr())).Interface() | ||
s := Fill(objPt) | ||
f.Set(reflect.ValueOf(s)) | ||
} | ||
} | ||
} | ||
} | ||
return reflect.Indirect(v).Interface() | ||
} |
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
Oops, something went wrong.