Skip to content

Commit

Permalink
Up to 100% of code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcos Serradilla Diez committed Jul 17, 2019
1 parent 11b3389 commit 941fb8b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
10 changes: 5 additions & 5 deletions contracts/Fundable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ contract Fundable is IFundable, ERC20 {
require(fundOperators[msg.sender][orderer] == false, "The operator is already authorized");

fundOperators[msg.sender][orderer] = true;
emit FundOperatorAuthorized(orderer, msg.sender);
emit FundOperatorAuthorized(msg.sender, orderer);
return true;
}

function revokeFundOperator(address orderer) external returns (bool) {
require(fundOperators[msg.sender][orderer], "The operator is already not authorized");

fundOperators[msg.sender][orderer] = false;
emit FundOperatorRevoked(orderer, msg.sender);
emit FundOperatorRevoked(msg.sender, orderer);
return true;
}

Expand All @@ -64,7 +64,7 @@ contract Fundable is IFundable, ERC20 {
) external returns (bool)
{
require(address(0) != walletToFund, "WalletToFund address must not be zero address");
require(_isFundOperatorFor(walletToFund, msg.sender), "This operator is not authorized");
require(_isFundOperatorFor(msg.sender, walletToFund), "This operator is not authorized");
return _orderFund(
operationId,
walletToFund,
Expand Down Expand Up @@ -171,7 +171,7 @@ contract Fundable is IFundable, ERC20 {
return true;
}

function _isFundOperatorFor(address walletToFund, address orderer) private view returns (bool) {
return fundOperators[walletToFund][orderer];
function _isFundOperatorFor(address operator, address from) private view returns (bool) {
return fundOperators[from][operator];
}
}
46 changes: 45 additions & 1 deletion test/Fundable.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ contract('Fundable', (accounts) => {
);
});

it('should revert if the contract payout agent calls it', async() => {
it('should revert if the contract fund operator calls it', async() => {
await truffleAssert.reverts(
fundable.cancelFund(
operationId,
Expand Down Expand Up @@ -619,5 +619,49 @@ contract('Fundable', (accounts) => {
assert.strictEqual(balanceOfWalletToFund.toNumber(), 1, 'Balance of wallet to fund not updated');
});
});

describe('authorizeFundOperator', async() => {
it('should authorize an operator and emit a FundOperatorAuthorized event', async() => {
const tx = await fundable.authorizeFundOperator(authorizedFundOperator, {from: from});

const isAuthorized = await fundable.isFundOperatorFor(authorizedFundOperator, from);
assert.strictEqual(isAuthorized, true, 'Operator has not been authorized');

truffleAssert.eventEmitted(tx, 'FundOperatorAuthorized', (_event) => {
return _event.orderer === authorizedFundOperator && _event.walletToFund === from;
});
});

it('should revert if an operator has already been authorized', async() => {
await fundable.authorizeFundOperator(authorizedFundOperator, {from: from});

await truffleAssert.reverts(
fundable.authorizeFundOperator(authorizedFundOperator, {from: from}),
'The operator is already authorized'
);
});
});

describe('revokeFundOperator', async() => {
it('should revert if an operator has not been authorized', async() => {
await truffleAssert.reverts(
fundable.revokeFundOperator(unauthorizedFundOperator, {from: from}),
'The operator is already not authorized'
);
});

it('should revoke the authorization of an operator and emit a FundOperatorRevoked event', async() => {
await fundable.authorizeFundOperator(unauthorizedFundOperator, {from: from});

const tx = await fundable.revokeFundOperator(unauthorizedFundOperator, {from: from});

const isAuthorized = await fundable.isFundOperatorFor(unauthorizedFundOperator, from);
assert.strictEqual(isAuthorized, false, 'Operator authorization has not been revoked');

truffleAssert.eventEmitted(tx, 'FundOperatorRevoked', (_event) => {
return _event.orderer === unauthorizedFundOperator && _event.walletToFund === from;
});
});
});

});

0 comments on commit 941fb8b

Please sign in to comment.