Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
altergui committed Sep 5, 2024
1 parent 3c11995 commit e4ba715
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
40 changes: 39 additions & 1 deletion vochain/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func setupTestBaseApplicationAndSigners(t *testing.T,
}

func TestSetAccountTx(t *testing.T) {
app, signers, err := setupTestBaseApplicationAndSigners(t, 10)
app, signers, err := setupTestBaseApplicationAndSigners(t, 11)
qt.Assert(t, err, qt.IsNil)
// set account 0
qt.Assert(t,
Expand Down Expand Up @@ -578,6 +578,44 @@ func TestSetAccountTx(t *testing.T) {
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)

// now we init signers[10] with 1000 tokens from faucet (signers[0])
// resulting balance should be 800 (because of the 200 txcost of createAccount)
// then "transfer" 700 of those to signers[9] via a faucet package issued by signers[10]
// used to setAccount
faucetPkg, err = GenerateFaucetPackage(signers[0], signers[10].Address(), 1000)
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, testSetAccountTx(t,
signers[10], signers[10].Address(), faucetPkg, app, "", uint32(0), true),
qt.IsNil,
)
signer10Account, err := app.State.GetAccount(signers[10].Address(), false)
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, signer10Account.Balance, qt.DeepEquals, uint64(1000-200))

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

faucetPkg, err = GenerateFaucetPackage(signers[10], signers[9].Address(), 1000-200+1)
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, testSetAccountTx(t,
signers[9], signers[9].Address(), faucetPkg, app, "ipfs://test", uint32(2), false),
qt.ErrorMatches, regexp.MustCompile(".*issuer address does not have enough balance.*"),
)

faucetPkg, err = GenerateFaucetPackage(signers[10], signers[9].Address(), 1000-200-50)
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, testSetAccountTx(t,
signers[9], signers[9].Address(), faucetPkg, app, "ipfs://test", uint32(2), false),
qt.IsNil,
)
signer10Account, err = app.State.GetAccount(signers[10].Address(), false)
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, signer10Account.Balance, qt.DeepEquals, uint64(50))
signer9Account, err = app.State.GetAccount(signers[9].Address(), false)
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, signer9Account.Balance, qt.DeepEquals, uint64(oldBalance+1000-200-50-200))
}

func testSetAccountTx(t *testing.T,
Expand Down
6 changes: 3 additions & 3 deletions vochain/transaction/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ func (t *TransactionHandler) checkAccountCanPayCost(txType models.TxType, vtx *v
return txSenderAcc, &txSenderAddress, nil
}

// checkFaucetPackageCanPayCost checks if the txFaucetPackage is a valid Faucet package issued for txSenderAddress and the account signing the faucet package has
// checkFaucetPackageAndTransfer checks if the txFaucetPackage is a valid Faucet package issued for txSenderAddress and the account signing the faucet package has
// enough funds for paying for the txCost.
// If forCommit is true, the faucet package balance is transferred to the txSender account.
// Returns false and no error if the faucet package does not exist. If it exists but there is an issue, returns false and the error.
Expand Down Expand Up @@ -661,11 +661,11 @@ func (t *TransactionHandler) checkFaucetPackageAndTransfer(txFaucetPackage *mode
if used {
return false, fmt.Errorf("faucet payload %x already used", keyHash)
}
if issuerAcc.Balance < faucetPayload.Amount+txCost {
if issuerAcc.Balance < faucetPayload.Amount {
return false, fmt.Errorf(
"issuer address does not have enough balance %d, required %d",
issuerAcc.Balance,
faucetPayload.Amount+txCost,
faucetPayload.Amount,
)
}

Expand Down

0 comments on commit e4ba715

Please sign in to comment.