Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into df-naming-conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfx90 authored May 16, 2019
2 parents 65a1a46 + 1f154a7 commit eb35059
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
6 changes: 3 additions & 3 deletions contracts/Accounts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,14 @@ contract Accounts is Data {
external
onlyAccountOwner(accountId)
{
address addr = accounts[accountId].owner;
uint64 balance = accounts[accountId].balance;

require(balance >= amount, "insufficient funds");
require(amount > 0, "amount should be nonzero");

balanceSub(accountId, amount);

token.transfer(addr, amount);
require(token.transfer(msg.sender, amount), "transfer failed");
}

/**
Expand All @@ -135,7 +134,6 @@ contract Accounts is Data {
function deposit(uint64 amount, uint256 accountId) external {
require(accountId < accounts.length || accountId == NEW_ACCOUNT_FLAG, "invalid accountId");
require(amount > 0, "amount should be positive");
require(token.transferFrom(msg.sender, address(this), amount), "transfer failed");

if (accountId == NEW_ACCOUNT_FLAG) {
// new account
Expand All @@ -145,6 +143,8 @@ contract Accounts is Data {
// existing account
balanceAdd(accountId, amount);
}

require(token.transferFrom(msg.sender, address(this), amount), "transfer failed");
}

/**
Expand Down
37 changes: 14 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"istanbul": "^0.4.5",
"solhint": "^2.0.0",
"standard": "^12.0.1",
"truffle-hdwallet-provider": "^1.0.6"
"truffle-hdwallet-provider": "1.0.6"
},
"standard": {
"globals": [
Expand Down
11 changes: 11 additions & 0 deletions test/test_accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ contract('Accounts', (addr) => {
assert.equal(y1 - y0, amount / 2)
})

it('Should reject withdrawals for existing accounts when sender is not the owner', async () => {
const amount = 100

await st.approve(bp.address, amount)
await bp.deposit(amount, newAccountFlag)
let id = await bp.getAccountsLength.call()
id = id.toNumber() - 1

await catchRevert(bp.withdraw(amount / 2, id, { from: a1 }))
})

it('Should reject withdrawals for invalid accounts', async () => {
const amount = 100

Expand Down

0 comments on commit eb35059

Please sign in to comment.