mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-10-14 00:59:21 +00:00
Add the PoPCycle concept (#208)
* added reissuance details, the concept of popepochs and popcycles Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
6a60b78b62
commit
cefd22f448
@ -1,19 +1,51 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"math"
|
||||
"math/big"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/store/prefix"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/planetmint/planetmint-go/config"
|
||||
"github.com/planetmint/planetmint-go/x/dao/types"
|
||||
)
|
||||
|
||||
func GetReissuanceCommand(assetID string, _ int64) string {
|
||||
return "reissueasset " + assetID + " 998.69000000"
|
||||
func GetPopNumber(blockHeight int64) float64 {
|
||||
return float64(blockHeight) / float64(config.GetConfig().PoPEpochs)
|
||||
}
|
||||
|
||||
func IsValidReissuanceCommand(reissuanceStr string, assetID string, _ int64) bool {
|
||||
expected := "reissueasset " + assetID + " 998.69000000"
|
||||
var PopsPerCycle float64
|
||||
|
||||
func init() {
|
||||
PopsPerCycle = 1051200.0
|
||||
}
|
||||
|
||||
func GetReissuanceAsStringValue(blockHeight int64) string {
|
||||
PopNumber := GetPopNumber(blockHeight)
|
||||
exactCycleID := PopNumber / PopsPerCycle
|
||||
|
||||
switch cycleID := math.Floor(exactCycleID); cycleID {
|
||||
case 0:
|
||||
return "998.69000000"
|
||||
case 1:
|
||||
return "499.34000000"
|
||||
case 2:
|
||||
return "249.67000000"
|
||||
case 3:
|
||||
return "124.83000000"
|
||||
case 4:
|
||||
return "62.42000000"
|
||||
default:
|
||||
return "0.0"
|
||||
}
|
||||
}
|
||||
|
||||
func GetReissuanceCommand(assetID string, blockHeight int64) string {
|
||||
return "reissueasset " + assetID + " " + GetReissuanceAsStringValue(blockHeight)
|
||||
}
|
||||
|
||||
func IsValidReissuanceCommand(reissuanceStr string, assetID string, blockHeight int64) bool {
|
||||
expected := "reissueasset " + assetID + " " + GetReissuanceAsStringValue(blockHeight)
|
||||
return reissuanceStr == expected
|
||||
}
|
||||
|
||||
|
@ -4,20 +4,21 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/planetmint/planetmint-go/config"
|
||||
keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/planetmint/planetmint-go/x/dao/keeper"
|
||||
daokeeper "github.com/planetmint/planetmint-go/x/dao/keeper"
|
||||
"github.com/planetmint/planetmint-go/x/dao/types"
|
||||
)
|
||||
|
||||
func createNReissuances(k *keeper.Keeper, ctx sdk.Context, n int) []types.Reissuance {
|
||||
func createNReissuances(k *daokeeper.Keeper, ctx sdk.Context, n int) []types.Reissuance {
|
||||
items := make([]types.Reissuance, n)
|
||||
for i := range items {
|
||||
items[i].BlockHeight = int64(i)
|
||||
items[i].Proposer = fmt.Sprintf("proposer_%v", i)
|
||||
items[i].Rawtx = keeper.GetReissuanceCommand("asset_id", int64(i))
|
||||
items[i].Rawtx = daokeeper.GetReissuanceCommand("asset_id", int64(i))
|
||||
items[i].TxID = ""
|
||||
k.StoreReissuance(ctx, items[i])
|
||||
}
|
||||
@ -34,3 +35,14 @@ func TestGetReissuances(t *testing.T) {
|
||||
assert.Equal(t, item, reissuance)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReissuanceValueComputation(t *testing.T) {
|
||||
t.Parallel()
|
||||
popsPerEpoch := float64(config.GetConfig().PoPEpochs)
|
||||
assert.Equal(t, "998.69000000", daokeeper.GetReissuanceAsStringValue(1))
|
||||
assert.Equal(t, "499.34000000", daokeeper.GetReissuanceAsStringValue(int64(daokeeper.PopsPerCycle*popsPerEpoch*1+1)))
|
||||
assert.Equal(t, "249.67000000", daokeeper.GetReissuanceAsStringValue(int64(daokeeper.PopsPerCycle*popsPerEpoch*2+1)))
|
||||
assert.Equal(t, "124.83000000", daokeeper.GetReissuanceAsStringValue(int64(daokeeper.PopsPerCycle*popsPerEpoch*3+1)))
|
||||
assert.Equal(t, "62.42000000", daokeeper.GetReissuanceAsStringValue(int64(daokeeper.PopsPerCycle*popsPerEpoch*4+1)))
|
||||
assert.Equal(t, "0.0", daokeeper.GetReissuanceAsStringValue(int64(daokeeper.PopsPerCycle*popsPerEpoch*5+1)))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user