forked from lino-network/lino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
can delegate to anyone and add delegate interest test (lino-network#287
) * can delegate to anyone and add delegate interest test * add voting power test * fix voter withdraw bug
- Loading branch information
Showing
3 changed files
with
144 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package global | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/lino-network/lino/test" | ||
"github.com/lino-network/lino/types" | ||
"github.com/tendermint/tendermint/crypto/secp256k1" | ||
|
||
"github.com/lino-network/lino/x/post" | ||
vote "github.com/lino-network/lino/x/vote" | ||
) | ||
|
||
func TestDelegateInterest(t *testing.T) { | ||
postUserPriv := secp256k1.GenPrivKey() | ||
donatorPriv := secp256k1.GenPrivKey() | ||
u1Priv := secp256k1.GenPrivKey() | ||
u2Priv := secp256k1.GenPrivKey() | ||
|
||
postUserName := "poster" | ||
donatorName := "donator" | ||
u1Name := "user1" | ||
u2Name := "user2" | ||
|
||
postID := "New Post" | ||
|
||
// to recover the coin day | ||
baseTime := time.Now().Unix() + 7200 | ||
lb := test.NewTestLinoBlockchain(t, test.DefaultNumOfVal) | ||
|
||
test.CreateAccount(t, donatorName, lb, 0, | ||
secp256k1.GenPrivKey(), donatorPriv, secp256k1.GenPrivKey(), "100000") | ||
test.CreateAccount(t, u1Name, lb, 1, | ||
secp256k1.GenPrivKey(), u1Priv, secp256k1.GenPrivKey(), "100000") | ||
test.CreateAccount(t, u2Name, lb, 2, | ||
secp256k1.GenPrivKey(), u2Priv, secp256k1.GenPrivKey(), "100000") | ||
test.CreateAccount(t, postUserName, lb, 3, | ||
secp256k1.GenPrivKey(), postUserPriv, secp256k1.GenPrivKey(), "100000") | ||
test.CreateTestPost( | ||
t, lb, postUserName, postID, 0, postUserPriv, "", "", "", "", "0", baseTime) | ||
|
||
donateMsg := post.NewDonateMsg( | ||
donatorName, types.LNO("2000"), postUserName, postID, "", "") | ||
u1DelegateMsg := vote.NewDelegateMsg(u1Name, u2Name, types.LNO("10000")) | ||
u2DelegateMsg := vote.NewDelegateMsg(u2Name, u1Name, types.LNO("40000")) | ||
|
||
test.SignCheckDeliver(t, lb, donateMsg, 0, true, donatorPriv, baseTime) | ||
test.SignCheckDeliver(t, lb, u1DelegateMsg, 0, true, u1Priv, baseTime) | ||
test.SignCheckDeliver(t, lb, u2DelegateMsg, 0, true, u2Priv, baseTime) | ||
|
||
test.CheckBalance(t, u1Name, lb, types.NewCoinFromInt64(89999*types.Decimals)) | ||
test.CheckBalance(t, u2Name, lb, types.NewCoinFromInt64(59999*types.Decimals)) | ||
|
||
// 3rd day | ||
baseTime += 3600 * 24 * 3 | ||
test.SimulateOneBlock(lb, baseTime) | ||
|
||
u1ClaimInterestMsg := vote.NewClaimInterestMsg(u1Name) | ||
u2ClaimInterestMsg := vote.NewClaimInterestMsg(u2Name) | ||
|
||
test.SignCheckDeliver(t, lb, u1ClaimInterestMsg, 1, true, u1Priv, baseTime) | ||
test.SignCheckDeliver(t, lb, u2ClaimInterestMsg, 1, true, u2Priv, baseTime) | ||
|
||
test.CheckBalance(t, u1Name, lb, types.NewCoinFromInt64((89999+0.15748)*types.Decimals)) | ||
test.CheckBalance(t, u2Name, lb, types.NewCoinFromInt64((59999+0.62992)*types.Decimals)) | ||
|
||
u1DelegateMsg = vote.NewDelegateMsg(u1Name, u2Name, types.LNO("20000")) | ||
u2StakeOutMsg := vote.NewStakeOutMsg(u2Name, types.LNO("10000")) | ||
u2DelegatorWithdrawMsg := vote.NewDelegatorWithdrawMsg(u2Name, u1Name, types.LNO("10000")) | ||
|
||
test.SignCheckDeliver(t, lb, u1DelegateMsg, 2, true, u1Priv, baseTime) | ||
test.SignCheckDeliver(t, lb, u2StakeOutMsg, 2, false, u2Priv, baseTime) | ||
test.SignCheckDeliver(t, lb, u2DelegatorWithdrawMsg, 3, true, u2Priv, baseTime) | ||
test.SignCheckDeliver(t, lb, donateMsg, 1, true, donatorPriv, baseTime) | ||
|
||
// 4th day | ||
baseTime += 3600 * 24 * 1 | ||
test.SimulateOneBlock(lb, baseTime) | ||
test.SignCheckDeliver(t, lb, donateMsg, 2, true, donatorPriv, baseTime) | ||
|
||
// 5th day | ||
baseTime += 3600 * 24 * 1 | ||
test.SimulateOneBlock(lb, baseTime) | ||
test.SignCheckDeliver(t, lb, donateMsg, 3, true, donatorPriv, baseTime) | ||
|
||
u1DelegatorWithdrawMsg := vote.NewDelegatorWithdrawMsg(u1Name, u2Name, types.LNO("30000")) | ||
u2DelegatorWithdrawMsg = vote.NewDelegatorWithdrawMsg(u2Name, u1Name, types.LNO("30000")) | ||
|
||
test.SignCheckDeliver(t, lb, u1DelegatorWithdrawMsg, 3, true, u1Priv, baseTime) | ||
test.SignCheckDeliver(t, lb, u2DelegatorWithdrawMsg, 4, true, u2Priv, baseTime) | ||
|
||
// 6th day | ||
baseTime += 3600 * 24 * 1 | ||
test.SimulateOneBlock(lb, baseTime) | ||
|
||
test.SignCheckDeliver(t, lb, u1ClaimInterestMsg, 4, true, u1Priv, baseTime) | ||
test.SignCheckDeliver(t, lb, u2ClaimInterestMsg, 5, true, u2Priv, baseTime) | ||
|
||
test.CheckBalance(t, u1Name, lb, types.NewCoinFromInt64((69999+1.10088)*types.Decimals)) | ||
test.CheckBalance(t, u2Name, lb, types.NewCoinFromInt64((59999+1.57332)*types.Decimals)) | ||
|
||
} |
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