Skip to content

Commit

Permalink
add test to send token to the same account
Browse files Browse the repository at this point in the history
  • Loading branch information
mariajdab committed Oct 31, 2023
1 parent 734dd3f commit 213280c
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions vochain/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,40 @@ func TestSendTokensTx(t *testing.T) {
qt.Assert(t, fromAcc.Balance, qt.Equals, uint64(890))
}

func TestSendTokensTxToTheSameAccount(t *testing.T) {
app := TestBaseApplication(t)

signer := ethereum.SignKeys{}
err := signer.Generate()
qt.Assert(t, err, qt.IsNil)

app.State.SetAccount(state.BurnAddress, &state.Account{})

err = app.State.SetTxBaseCost(models.TxType_SEND_TOKENS, 10)
qt.Assert(t, err, qt.IsNil)

err = app.State.CreateAccount(signer.Address(), "ipfs://", [][]byte{}, 0)
qt.Assert(t, err, qt.IsNil)

err = app.State.MintBalance(&vochaintx.TokenTransfer{
ToAddress: signer.Address(),
Amount: 1000,
})
qt.Assert(t, err, qt.IsNil)
testCommitState(t, app)

// try to send same account should return an error?
err = testSendTokensTx(t, &signer, app, signer.Address(), 20, 0)
qt.Assert(t, err, qt.IsNil)

// get from acc
fromAcc, err := app.State.GetAccount(signer.Address(), false)
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, fromAcc, qt.IsNotNil)
// the balance add 10 and reduce 10 from the cost this should not happpen
qt.Assert(t, fromAcc.Balance, qt.Equals, uint64(1010))
}

func testSendTokensTx(t *testing.T,
signer *ethereum.SignKeys,
app *BaseApplication,
Expand Down

0 comments on commit 213280c

Please sign in to comment.