github.com/lino-network/lino@v0.6.11/test/post/donation_test.go (about) 1 package post 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/lino-network/lino/test" 8 "github.com/lino-network/lino/types" 9 10 // acc "github.com/lino-network/lino/x/account" 11 post "github.com/lino-network/lino/x/post/types" 12 "github.com/tendermint/tendermint/crypto/secp256k1" 13 ) 14 15 // test donate to a normal post 16 func TestNormalDonation(t *testing.T) { 17 newPostUserTransactionPriv := secp256k1.GenPrivKey() 18 newPostUser := "poster" 19 postID := "New Post" 20 21 newDonateUserTransactionPriv := secp256k1.GenPrivKey() 22 newDonateUser := "donator" 23 baseT := time.Unix(0, 0).Add(3600 * time.Second) 24 baseTime := baseT.Unix() 25 lb := test.NewTestLinoBlockchain(t, test.DefaultNumOfVal, baseT) 26 27 test.CreateAccount(t, newPostUser, lb, 0, 28 secp256k1.GenPrivKey(), newPostUserTransactionPriv, "100") 29 test.CreateAccount(t, newDonateUser, lb, 1, 30 secp256k1.GenPrivKey(), newDonateUserTransactionPriv, "100") 31 32 test.CreateTestPost( 33 t, lb, newPostUser, postID, 1, newPostUserTransactionPriv, baseTime) 34 35 test.CheckBalance(t, newPostUser, lb, types.NewCoinFromInt64(99*types.Decimals)) 36 test.CheckBalance(t, newDonateUser, lb, types.NewCoinFromInt64(99*types.Decimals)) 37 38 donateMsg := post.NewDonateMsg( 39 newDonateUser, types.LNO("50"), newPostUser, postID, "", "") 40 41 test.SignCheckDeliver(t, lb, donateMsg, 1, true, newDonateUserTransactionPriv, baseTime) 42 43 test.CheckBalance(t, newDonateUser, lb, types.NewCoinFromInt64(49*types.Decimals)) 44 test.CheckBalance(t, newPostUser, lb, types.NewCoinFromInt64(9900000+4505000)) // 90.1% * 50 45 }