Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: upgrade fundraising to 0.3.0 #771

Merged
merged 8 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func New(
&stakingKeeper, govRouter,
)

app.FundraisingKeeper = *fundraisingkeeper.NewKeeper(
app.FundraisingKeeper = fundraisingkeeper.NewKeeper(
appCodec,
keys[fundraisingtypes.StoreKey],
keys[fundraisingtypes.MemStoreKey],
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/spf13/cast v1.4.1
github.com/spf13/cobra v1.4.0
github.com/stretchr/testify v1.7.1
github.com/tendermint/fundraising v0.2.0
github.com/tendermint/fundraising v0.3.0
github.com/tendermint/tendermint v0.34.19
github.com/tendermint/tm-db v0.6.7
google.golang.org/genproto v0.0.0-20220317150908-0efb43f6373e
Expand Down Expand Up @@ -42,7 +42,7 @@ require (
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/coinbase/rosetta-sdk-go v0.7.0 // indirect
github.com/confio/ics23/go v0.6.6 // indirect
github.com/confio/ics23/go v0.7.0 // indirect
github.com/containerd/cgroups v1.0.3 // indirect
github.com/containerd/containerd v1.6.2 // indirect
github.com/cosmos/btcutil v1.0.4 // indirect
Expand Down Expand Up @@ -149,6 +149,7 @@ require (
github.com/tendermint/btcd v0.1.1 // indirect
github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tendermint/spm v0.1.8 // indirect
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce // indirect
github.com/xanzy/ssh-agent v0.2.1 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
Expand Down
282 changes: 277 additions & 5 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions testutil/keeper/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func (i initializer) Fundraising(
authKeeper authkeeper.AccountKeeper,
bankKeeper bankkeeper.Keeper,
disKeeper distrkeeper.Keeper,
) *fundraisingkeeper.Keeper {
) fundraisingkeeper.Keeper {
storeKey := sdk.NewKVStoreKey(fundraisingtypes.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(fundraisingtypes.MemStoreKey)

Expand All @@ -387,7 +387,7 @@ func (i initializer) Fundraising(

func (i initializer) Participation(
paramKeeper paramskeeper.Keeper,
fundraisingKeeper *fundraisingkeeper.Keeper,
fundraisingKeeper fundraisingkeeper.Keeper,
stakingKeeper stakingkeeper.Keeper,
) *participationkeeper.Keeper {
storeKey := sdk.NewKVStoreKey(participationtypes.StoreKey)
Expand Down
2 changes: 1 addition & 1 deletion testutil/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type TestKeepers struct {
BankKeeper bankkeeper.Keeper
IBCKeeper *ibckeeper.Keeper
StakingKeeper stakingkeeper.Keeper
FundraisingKeeper *fundraisingkeeper.Keeper
FundraisingKeeper fundraisingkeeper.Keeper
ParticipationKeeper *participationkeeper.Keeper
}

Expand Down
48 changes: 10 additions & 38 deletions x/participation/module_simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@ import (
)

const (
defaultWeightMsgCreateAuction int = 20
defaultWeightMsgParticipate int = 50
defaultWeightMsgCancelAuction int = 20
defaultWeightMsgWithdrawAllocations int = 50

opWeightMsgCreateAuction = "op_weight_create_auction"
opWeightMsgParticipate = "op_weight_msg_participate"
opWeightMsgCancelAuction = "op_weight_cancel_auction"
opWeightMsgWithdrawAllocations = "op_weight_withdraw_allocations"

// this line is used by starport scaffolding # simapp/module/const
Expand Down Expand Up @@ -69,56 +65,32 @@ func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {}

// WeightedOperations returns the all the gov module operations with their respective weights.
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
operations := make([]simtypes.WeightedOperation, 0)

var (
weightMsgParticipate int
weightMsgCreateAuction int
weightMsgWithdrawAllocations int
weightMsgCancelAuction int
)

simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgParticipate, &weightMsgParticipate, nil,
func(_ *rand.Rand) {
weightMsgParticipate = defaultWeightMsgParticipate
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgParticipate,
participationsim.SimulateMsgParticipate(am.accountKeeper, am.bankKeeper, am.fundraisingKeeper, am.keeper),
))

simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgCreateAuction, &weightMsgCreateAuction, nil,
func(_ *rand.Rand) {
weightMsgCreateAuction = defaultWeightMsgCreateAuction
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgCreateAuction,
participationsim.SimulateCreateAuction(am.accountKeeper, am.bankKeeper, am.fundraisingKeeper, am.keeper),
))

simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgWithdrawAllocations, &weightMsgWithdrawAllocations, nil,
func(_ *rand.Rand) {
weightMsgWithdrawAllocations = defaultWeightMsgWithdrawAllocations
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgWithdrawAllocations,
participationsim.SimulateMsgWithdrawAllocations(am.accountKeeper, am.bankKeeper, am.fundraisingKeeper, am.keeper),
))

simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgCancelAuction, &weightMsgCancelAuction, nil,
func(_ *rand.Rand) {
weightMsgCancelAuction = defaultWeightMsgCancelAuction
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgCancelAuction,
participationsim.SimulateMsgCancelAuction(am.accountKeeper, am.bankKeeper, am.fundraisingKeeper),
))

// this line is used by starport scaffolding # simapp/module/operation

return operations
return []simtypes.WeightedOperation{
simulation.NewWeightedOperation(
weightMsgParticipate,
participationsim.SimulateMsgParticipate(am.accountKeeper, am.bankKeeper, am.fundraisingKeeper, am.keeper),
),
simulation.NewWeightedOperation(
weightMsgWithdrawAllocations,
participationsim.SimulateMsgWithdrawAllocations(am.accountKeeper, am.bankKeeper, am.fundraisingKeeper, am.keeper),
),
}
}
83 changes: 39 additions & 44 deletions x/participation/simulation/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,34 +77,31 @@ func TestRandomAuctionStandby(t *testing.T) {
endTime := ctx.BlockTime().Add(time.Hour * 24 * 7)

// set custom auction with status AuctionStarted
var allowedBidders []fundraisingtypes.AllowedBidder
endTimes := []time.Time{endTime}
ba := &fundraisingtypes.BaseAuction{
Id: 0,
Type: fundraisingtypes.AuctionTypeFixedPrice,
AllowedBidders: allowedBidders,
Auctioneer: accs[0].Address.String(),
StartTime: startTime,
EndTimes: endTimes,
Status: fundraisingtypes.AuctionStatusStarted,
Id: 0,
Type: fundraisingtypes.AuctionTypeFixedPrice,
Auctioneer: accs[0].Address.String(),
StartTime: startTime,
EndTimes: endTimes,
Status: fundraisingtypes.AuctionStatusStarted,
}
auction := fundraisingtypes.NewFixedPriceAuction(ba)
auction := fundraisingtypes.NewFixedPriceAuction(ba, sample.Coin(r))
tk.FundraisingKeeper.SetAuction(ctx, auction)

// set custom auction with status AuctionCancelled
ba = &fundraisingtypes.BaseAuction{
Id: 1,
Type: fundraisingtypes.AuctionTypeFixedPrice,
AllowedBidders: allowedBidders,
Auctioneer: accs[0].Address.String(),
StartTime: startTime,
EndTimes: endTimes,
Status: fundraisingtypes.AuctionStatusCancelled,
Id: 1,
Type: fundraisingtypes.AuctionTypeFixedPrice,
Auctioneer: accs[0].Address.String(),
StartTime: startTime,
EndTimes: endTimes,
Status: fundraisingtypes.AuctionStatusCancelled,
}
auction = fundraisingtypes.NewFixedPriceAuction(ba)
auction = fundraisingtypes.NewFixedPriceAuction(ba, sample.Coin(r))
tk.FundraisingKeeper.SetAuction(ctx, auction)

_, found := participationsim.RandomAuctionStandby(ctx, r, *tk.FundraisingKeeper)
_, found := participationsim.RandomAuctionStandby(ctx, r, tk.FundraisingKeeper)
require.False(t, found)
})

Expand All @@ -119,15 +116,15 @@ func TestRandomAuctionStandby(t *testing.T) {
auction1, found := tk.FundraisingKeeper.GetAuction(ctx, auctionID1)
require.True(t, found)

got, found := participationsim.RandomAuctionStandby(ctx, r, *tk.FundraisingKeeper)
got, found := participationsim.RandomAuctionStandby(ctx, r, tk.FundraisingKeeper)
require.True(t, found)
require.Equal(t, auction1, got)
})

t.Run("no auctions", func(t *testing.T) {
ctx, tk, _ := testkeeper.NewTestSetup(t)

_, found := participationsim.RandomAuctionStandby(ctx, r, *tk.FundraisingKeeper)
_, found := participationsim.RandomAuctionStandby(ctx, r, tk.FundraisingKeeper)
require.False(t, found)
})
}
Expand All @@ -146,7 +143,7 @@ func TestRandomAuctionParticipationEnabled(t *testing.T) {
tk.ParticipationKeeper.SetParams(ctx, params)

t.Run("no auctions", func(t *testing.T) {
_, found := participationsim.RandomAuctionParticipationEnabled(ctx, r, *tk.FundraisingKeeper, *tk.ParticipationKeeper)
_, found := participationsim.RandomAuctionParticipationEnabled(ctx, r, tk.FundraisingKeeper, *tk.ParticipationKeeper)
require.False(t, found)
})

Expand All @@ -160,7 +157,7 @@ func TestRandomAuctionParticipationEnabled(t *testing.T) {
_, found := tk.FundraisingKeeper.GetAuction(ctx, auctionID)
require.True(t, found)

_, found = participationsim.RandomAuctionParticipationEnabled(ctx, r, *tk.FundraisingKeeper, *tk.ParticipationKeeper)
_, found = participationsim.RandomAuctionParticipationEnabled(ctx, r, tk.FundraisingKeeper, *tk.ParticipationKeeper)
require.False(t, found)
})

Expand All @@ -174,7 +171,7 @@ func TestRandomAuctionParticipationEnabled(t *testing.T) {
auction, found := tk.FundraisingKeeper.GetAuction(ctx, auctionID)
require.True(t, found)

got, found := participationsim.RandomAuctionParticipationEnabled(ctx, r, *tk.FundraisingKeeper, *tk.ParticipationKeeper)
got, found := participationsim.RandomAuctionParticipationEnabled(ctx, r, tk.FundraisingKeeper, *tk.ParticipationKeeper)
require.True(t, found)
require.Equal(t, auction, got)
})
Expand All @@ -197,38 +194,36 @@ func TestRandomAuctionWithdrawEnabled(t *testing.T) {
tk.ParticipationKeeper.SetParams(ctx, params)

t.Run("no auctions", func(t *testing.T) {
_, found := participationsim.RandomAuctionWithdrawEnabled(ctx, r, *tk.FundraisingKeeper, *tk.ParticipationKeeper)
_, found := participationsim.RandomAuctionWithdrawEnabled(ctx, r, tk.FundraisingKeeper, *tk.ParticipationKeeper)
require.False(t, found)
})

// populate keeper with some invalid auctions
var allowedBidders []fundraisingtypes.AllowedBidder
endTimes := []time.Time{endTime}
ba := &fundraisingtypes.BaseAuction{
Id: 0,
Type: fundraisingtypes.AuctionTypeFixedPrice,
AllowedBidders: allowedBidders,
Auctioneer: accs[0].Address.String(),
StartTime: invalidStartTime, // started, but withdrawal delay not reached
EndTimes: endTimes,
Status: fundraisingtypes.AuctionStatusStarted,
Id: 0,
Type: fundraisingtypes.AuctionTypeFixedPrice,
Auctioneer: accs[0].Address.String(),
StartTime: invalidStartTime, // started, but withdrawal delay not reached
EndTimes: endTimes,
Status: fundraisingtypes.AuctionStatusStarted,
}
invalidAuction := fundraisingtypes.NewFixedPriceAuction(ba)
invalidAuction := fundraisingtypes.NewFixedPriceAuction(ba, sample.Coin(r))
tk.FundraisingKeeper.SetAuction(ctx, invalidAuction)

ba = &fundraisingtypes.BaseAuction{
Id: 1,
Type: fundraisingtypes.AuctionTypeFixedPrice,
AllowedBidders: allowedBidders,
Auctioneer: accs[0].Address.String(),
StartTime: invalidStartTime.Add(time.Hour), // not yet started, but withdrawal delay not reached
EndTimes: endTimes,
Status: fundraisingtypes.AuctionStatusStandBy,
Id: 1,
Type: fundraisingtypes.AuctionTypeFixedPrice,
Auctioneer: accs[0].Address.String(),
StartTime: invalidStartTime.Add(time.Hour), // not yet started, but withdrawal delay not reached
EndTimes: endTimes,
Status: fundraisingtypes.AuctionStatusStandBy,
}
invalidAuction = fundraisingtypes.NewFixedPriceAuction(ba)
invalidAuction = fundraisingtypes.NewFixedPriceAuction(ba, sample.Coin(r))
tk.FundraisingKeeper.SetAuction(ctx, invalidAuction)

t.Run("no auction to be found that satisfy requirements", func(t *testing.T) {
_, found := participationsim.RandomAuctionWithdrawEnabled(ctx, r, *tk.FundraisingKeeper, *tk.ParticipationKeeper)
_, found := participationsim.RandomAuctionWithdrawEnabled(ctx, r, tk.FundraisingKeeper, *tk.ParticipationKeeper)
require.False(t, found)
})

Expand All @@ -239,7 +234,7 @@ func TestRandomAuctionWithdrawEnabled(t *testing.T) {
require.True(t, found)

t.Run("find auction where withdrawal delay has passed", func(t *testing.T) {
foundAuction, found := participationsim.RandomAuctionWithdrawEnabled(ctx, r, *tk.FundraisingKeeper, *tk.ParticipationKeeper)
foundAuction, found := participationsim.RandomAuctionWithdrawEnabled(ctx, r, tk.FundraisingKeeper, *tk.ParticipationKeeper)
require.True(t, found)
require.Equal(t, validAuction, foundAuction)
require.True(t, ctx.BlockTime().After(foundAuction.GetStartTime().Add(withdrawalDelay)))
Expand All @@ -251,7 +246,7 @@ func TestRandomAuctionWithdrawEnabled(t *testing.T) {
tk.FundraisingKeeper.SetAuction(ctx, validAuction)

t.Run("find cancelled auction", func(t *testing.T) {
foundAuction, found := participationsim.RandomAuctionWithdrawEnabled(ctx, r, *tk.FundraisingKeeper, *tk.ParticipationKeeper)
foundAuction, found := participationsim.RandomAuctionWithdrawEnabled(ctx, r, tk.FundraisingKeeper, *tk.ParticipationKeeper)
require.True(t, found)
require.Equal(t, validAuction, foundAuction)
require.Equal(t, fundraisingtypes.AuctionStatusCancelled, foundAuction.GetStatus())
Expand Down