Commit 4f20a53d authored by linj's avatar linj

add test

parent 5da5bfd3
...@@ -41,6 +41,9 @@ var ( ...@@ -41,6 +41,9 @@ var (
func TestToken(t *testing.T) { func TestToken(t *testing.T) {
types.SetTitleOnlyForTest("chain33") types.SetTitleOnlyForTest("chain33")
tokenTotal := int64(10000 * 1e8)
tokenBurn := int64(10 * 1e8)
tokenMint := int64(20 * 1e8)
total := int64(100000) total := int64(100000)
accountA := types.Account{ accountA := types.Account{
Balance: total, Balance: total,
...@@ -93,7 +96,7 @@ func TestToken(t *testing.T) { ...@@ -93,7 +96,7 @@ func TestToken(t *testing.T) {
Name: Symbol, Name: Symbol,
Symbol: Symbol, Symbol: Symbol,
Introduction: Symbol, Introduction: Symbol,
Total: 10000 * 1e8, Total: tokenTotal,
Price: 0, Price: 0,
Owner: string(Nodes[0]), Owner: string(Nodes[0]),
Category: pty.CategoryMintBurnSupport, Category: pty.CategoryMintBurnSupport,
...@@ -146,6 +149,9 @@ func TestToken(t *testing.T) { ...@@ -146,6 +149,9 @@ func TestToken(t *testing.T) {
for _, kv := range receipt.KV { for _, kv := range receipt.KV {
stateDB.Set(kv.Key, kv.Value) stateDB.Set(kv.Key, kv.Value)
} }
accDB, _ := account.NewAccountDB(pty.TokenX, Symbol, stateDB)
accChcek := accDB.LoadAccount(string(Nodes[0]))
assert.Equal(t, tokenTotal, accChcek.Balance)
receiptDate = &types.ReceiptData{Ty: receipt.Ty, Logs: receipt.Logs} receiptDate = &types.ReceiptData{Ty: receipt.Ty, Logs: receipt.Logs}
set, err = exec.ExecLocal(createTx2, receiptDate, int(1)) set, err = exec.ExecLocal(createTx2, receiptDate, int(1))
...@@ -155,7 +161,7 @@ func TestToken(t *testing.T) { ...@@ -155,7 +161,7 @@ func TestToken(t *testing.T) {
// mint burn // mint burn
p3 := &pty.TokenMint{ p3 := &pty.TokenMint{
Symbol: Symbol, Symbol: Symbol,
Amount: 6 * 1e8, Amount: tokenMint,
} }
//v, _ := types.PBToJSON(p1) //v, _ := types.PBToJSON(p1)
createTx3, err := types.CallCreateTransaction(pty.TokenX, "TokenMint", p3) createTx3, err := types.CallCreateTransaction(pty.TokenX, "TokenMint", p3)
...@@ -176,6 +182,9 @@ func TestToken(t *testing.T) { ...@@ -176,6 +182,9 @@ func TestToken(t *testing.T) {
stateDB.Set(kv.Key, kv.Value) stateDB.Set(kv.Key, kv.Value)
} }
accChcek = accDB.LoadAccount(string(Nodes[0]))
assert.Equal(t, tokenTotal+tokenMint, accChcek.Balance)
receiptDate = &types.ReceiptData{Ty: receipt.Ty, Logs: receipt.Logs} receiptDate = &types.ReceiptData{Ty: receipt.Ty, Logs: receipt.Logs}
set, err = exec.ExecLocal(createTx3, receiptDate, int(1)) set, err = exec.ExecLocal(createTx3, receiptDate, int(1))
assert.Nil(t, err) assert.Nil(t, err)
...@@ -183,7 +192,7 @@ func TestToken(t *testing.T) { ...@@ -183,7 +192,7 @@ func TestToken(t *testing.T) {
p4 := &pty.TokenBurn{ p4 := &pty.TokenBurn{
Symbol: Symbol, Symbol: Symbol,
Amount: 18, Amount: tokenBurn,
} }
//v, _ := types.PBToJSON(p1) //v, _ := types.PBToJSON(p1)
createTx4, err := types.CallCreateTransaction(pty.TokenX, "TokenBurn", p4) createTx4, err := types.CallCreateTransaction(pty.TokenX, "TokenBurn", p4)
...@@ -203,6 +212,8 @@ func TestToken(t *testing.T) { ...@@ -203,6 +212,8 @@ func TestToken(t *testing.T) {
for _, kv := range receipt.KV { for _, kv := range receipt.KV {
stateDB.Set(kv.Key, kv.Value) stateDB.Set(kv.Key, kv.Value)
} }
accChcek = accDB.LoadAccount(string(Nodes[0]))
assert.Equal(t, tokenTotal+tokenMint-tokenBurn, accChcek.Balance)
receiptDate = &types.ReceiptData{Ty: receipt.Ty, Logs: receipt.Logs} receiptDate = &types.ReceiptData{Ty: receipt.Ty, Logs: receipt.Logs}
set, err = exec.ExecLocal(createTx4, receiptDate, int(1)) set, err = exec.ExecLocal(createTx4, receiptDate, int(1))
......
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