Commit 6e2e4954 authored by linj's avatar linj Committed by vipwzw

test all means

parent ed0c6ba6
......@@ -6,10 +6,12 @@ import (
"github.com/stretchr/testify/assert"
pty "github.com/33cn/plugin/plugin/dapp/unfreeze/types"
"github.com/33cn/chain33/types"
)
func TestCalcFrozen(t *testing.T) {
m, err := newMeans("LeftProportion", 1)
types.SetTitleOnlyForTest("chain33")
m, err := newMeans("LeftProportion", 15000000)
assert.Nil(t, err)
assert.NotNil(t, m)
......@@ -66,3 +68,115 @@ func TestCalcFrozen(t *testing.T) {
})
}
}
func TestLeftV1(t *testing.T) {
cases := []struct {
start int64
now int64
period int64
total int64
tenThousandth int64
expect int64
}{
{10000, 10001, 10, 10000, 2, 9998},
{10000, 10011, 10, 10000, 2, 9996},
{10000, 10001, 10, 1e17, 2, 9998 * 1e13},
{10000, 10011, 10, 1e17, 2, 9998 * 9998 * 1e9},
}
for _, c := range cases {
c := c
t.Run("test LeftProportionV1", func(t *testing.T) {
create := pty.UnfreezeCreate{
StartTime: c.start,
AssetExec: "coins",
AssetSymbol: "bty",
TotalCount: c.total,
Beneficiary: "x",
Means: pty.LeftProportionX,
MeansOpt: &pty.UnfreezeCreate_LeftProportion{
LeftProportion: &pty.LeftProportion{
Period: c.period,
TenThousandth: c.tenThousandth,
},
},
}
u := &pty.Unfreeze{
TotalCount: c.total,
Means: pty.LeftProportionX,
StartTime: c.start,
MeansOpt: &pty.Unfreeze_LeftProportion{
LeftProportion: &pty.LeftProportion{
Period: c.period,
TenThousandth: c.tenThousandth,
},
},
}
m := leftProportion{}
u, err := m.setOpt(u, &create)
assert.Nil(t, err)
f, err := m.calcFrozen(u, c.now)
assert.Nil(t, err)
assert.Equal(t, c.expect, f)
})
}
}
func TestFixV1(t *testing.T) {
cases := []struct {
start int64
now int64
period int64
total int64
amount int64
expect int64
}{
{10000, 10001, 10, 10000, 2, 9998},
{10000, 10011, 10, 10000, 2, 9996},
{10000, 10001, 10, 1e17, 2, 1e17 -2},
{10000, 10011, 10, 1e17, 2, 1e17 -4},
}
for _, c := range cases {
c := c
t.Run("test FixAmountV1", func(t *testing.T) {
create := pty.UnfreezeCreate{
StartTime: c.start,
AssetExec: "coins",
AssetSymbol: "bty",
TotalCount: c.total,
Beneficiary: "x",
Means: pty.FixAmountX,
MeansOpt: &pty.UnfreezeCreate_FixAmount{
FixAmount: &pty.FixAmount{
Period: c.period,
Amount: c.amount,
},
},
}
u := &pty.Unfreeze{
TotalCount: c.total,
Means: pty.FixAmountX,
StartTime: c.start,
MeansOpt: &pty.Unfreeze_FixAmount{
FixAmount: &pty.FixAmount{
Period: c.period,
Amount: c.amount,
},
},
}
m := fixAmount{}
u, err := m.setOpt(u, &create)
assert.Nil(t, err)
f, err := m.calcFrozen(u, c.now)
assert.Nil(t, err)
assert.Equal(t, c.expect, f)
})
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment