Skip to content

Commit

Permalink
Merge pull request #185 from gulshanvasnani/test_hardcode_prefix
Browse files Browse the repository at this point in the history
Test to verify call prefixes
  • Loading branch information
benjaminbollen authored Mar 28, 2019
2 parents 4d76ba4 + c8d1551 commit 4817bb0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/test_lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,31 @@ module.exports = {
return { exTxHash, exTxSignature };
},

verifyCallPrefixConstant(methodName, callPrefix, contractName) {
const contract = artifacts.require(contractName);

let methodConcat = methodName.concat('(');
let input;
let abiMethod;

for (let i = 0; i < contract.abi.length; i += 1) {
abiMethod = contract.abi[i];
if (abiMethod.name === methodName) {
for (let j = 0; j < abiMethod.inputs.length - 1; j += 1) {
input = abiMethod.inputs[j].type;
methodConcat = methodConcat.concat(input, ',');
}
input = abiMethod.inputs[abiMethod.inputs.length - 1].type;
methodConcat += input;
}
}
methodConcat = methodConcat.concat(')');

const expectedPrefix = web3.utils.soliditySha3(methodConcat).substring(0, 10);

assert.strictEqual(expectedPrefix, callPrefix, `Expected ${methodName} callprefix is ${callPrefix} but got ${expectedPrefix}`);
},

getParamFromTxEvent: (
transaction, contractAddress, eventName, paramName,
) => {
Expand Down
20 changes: 20 additions & 0 deletions test/token_holder/execute_rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const { TokenHolderUtils } = require('./utils.js');
const { Event } = require('../test_lib/event_decoder');
const { AccountProvider } = require('../test_lib/utils.js');

const TokenHolder = artifacts.require('./TokenHolder.sol');

const CustomRuleDouble = artifacts.require('CustomRuleDouble');

const sessionPublicKey1 = '0x62502C4DF73935D0D10054b0Fb8cC036534C6fb0';
Expand Down Expand Up @@ -958,4 +960,22 @@ contract('TokenHolder::executeRule', async () => {
);
});
});

contract('Verify call prefix constants', async () => {
it('Verify EXECUTE_RULE_CALLPREFIX constant', async () => {
const tokenHolder = await TokenHolder.new();
const tokenHolderExecuteRuleCallPrefix = await tokenHolder.EXECUTE_RULE_CALLPREFIX();
const methodName = 'executeRule';

Utils.verifyCallPrefixConstant(methodName, tokenHolderExecuteRuleCallPrefix, 'TokenHolder');
});

it('Verify EXECUTE_REDEMPTION_CALLPREFIX constant', async () => {
const tokenHolder = await TokenHolder.new();
const tokenHolderExecuteRuleCallPrefix = await tokenHolder.EXECUTE_REDEMPTION_CALLPREFIX();
const methodName = 'executeRedemption';

Utils.verifyCallPrefixConstant(methodName, tokenHolderExecuteRuleCallPrefix, 'TokenHolder');
});
});
});
10 changes: 10 additions & 0 deletions test/user_wallet_factory/create_user_wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,14 @@ contract('UserWalletFactory::createUserWallet', async (accounts) => {
});
});
});

contract('Verify call prefix constants', async () => {
it('Verify TOKENHOLDER_SETUP_CALLPREFIX constant', async () => {
const userWalletFactory = await UserWalletFactory.new();
const tokenHolderSetupCallPrefix = await userWalletFactory.TOKENHOLDER_SETUP_CALLPREFIX();
const methodName = 'setup';

Utils.verifyCallPrefixConstant(methodName, tokenHolderSetupCallPrefix, 'TokenHolder');
});
});
});

0 comments on commit 4817bb0

Please sign in to comment.