Skip to content

Commit

Permalink
fixup! fixup! extend faucet package support for other transactions
Browse files Browse the repository at this point in the history
add more tests to TestSetAccountTx
  • Loading branch information
altergui committed Sep 5, 2024
1 parent 65cb171 commit 3c11995
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions vochain/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"math/rand"
"regexp"
"testing"

cometabcitypes "github.com/cometbft/cometbft/abci/types"
Expand Down Expand Up @@ -539,6 +540,44 @@ func TestSetAccountTx(t *testing.T) {
qt.Assert(t, signer9Account.Balance, qt.DeepEquals, uint64(1))
qt.Assert(t, signer9Account.Nonce, qt.DeepEquals, uint32(1))
qt.Assert(t, signer9Account.InfoURI, qt.CmpEquals(), infoURI3)

// third should not work: try using an insufficiente faucet package (100) for a set account info tx
// because tx cost 200
faucetPkg, err = GenerateFaucetPackage(signers[0], signers[9].Address(), 100)
qt.Assert(t, err, qt.IsNil)
infoURI4 := "ipfs://newInfoUri4"
qt.Assert(t, testSetAccountTx(t,
signers[9], signers[9].Address(), faucetPkg, app, infoURI4, uint32(1), false),
qt.ErrorMatches, regexp.MustCompile(".*"+state.ErrNotEnoughBalance.Error()),
)

signer9Account, err = app.State.GetAccount(signers[9].Address(), false)
qt.Assert(t, err, qt.IsNil)

// the result should be the 100 tokens are now added to the balance, but the infoURI remains unchanged.
qt.Assert(t, signer9Account, qt.IsNotNil)
qt.Assert(t, signer9Account.Balance, qt.DeepEquals, uint64(101))
qt.Assert(t, signer9Account.Nonce, qt.DeepEquals, uint32(1))
qt.Assert(t, signer9Account.InfoURI, qt.CmpEquals(), infoURI3)

// now this should work: try again using a small faucet package (120) for a set account info tx
// but adding faucet (120) + balance (101) is enough to cover the tx cost of 200
faucetPkg, err = GenerateFaucetPackage(signers[0], signers[9].Address(), 120)
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, testSetAccountTx(t,
signers[9], signers[9].Address(), faucetPkg, app, infoURI4, uint32(1), false),
qt.IsNil,
)

signer9Account, err = app.State.GetAccount(signers[9].Address(), false)
qt.Assert(t, err, qt.IsNil)

// the resulting balance should be 21 (and the infoURI is updated)
// i.e. the tokens from balance + faucet (120+101=221) minus the consumed txcost (200),
qt.Assert(t, signer9Account, qt.IsNotNil)
qt.Assert(t, signer9Account.Balance, qt.DeepEquals, uint64(21))
qt.Assert(t, signer9Account.Nonce, qt.DeepEquals, uint32(2))
qt.Assert(t, signer9Account.InfoURI, qt.CmpEquals(), infoURI4)
}

func testSetAccountTx(t *testing.T,
Expand Down

0 comments on commit 3c11995

Please sign in to comment.