From 0582e905586f880afd106cda8298d2f231a019bc Mon Sep 17 00:00:00 2001 From: Gulshan Vasnani Date: Wed, 27 Mar 2019 15:33:08 +0530 Subject: [PATCH 1/2] Added test to verify call prefix constant in tokenholder and userwalletfactory contract --- test/test_lib/utils.js | 27 ++++++++++++++++++- test/token_holder/execute_rule.js | 20 ++++++++++++++ .../user_wallet_factory/create_user_wallet.js | 12 +++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/test/test_lib/utils.js b/test/test_lib/utils.js index 4c4149a..04b0539 100644 --- a/test/test_lib/utils.js +++ b/test/test_lib/utils.js @@ -167,6 +167,31 @@ module.exports = { return { exTxHash, exTxSignature }; }, + verifyCallPrefixConstant(methodName, callPrefix, contractName) { + const contract = artifacts.require(contractName); + + let methodConcat = methodName.concat('('); + let input, abiMethod; + + for(let i = 0; i < contract.abi.length; i++) { + abiMethod = contract.abi[i]; + if(abiMethod.name === methodName) { + for(let j=0; j < abiMethod.inputs.length - 1; j ++) { + 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, ) => { @@ -194,5 +219,5 @@ module.exports = { assert(typeof param !== 'undefined'); return param; - }, + } }; diff --git a/test/token_holder/execute_rule.js b/test/token_holder/execute_rule.js index 53d49eb..a4275d7 100644 --- a/test/token_holder/execute_rule.js +++ b/test/token_holder/execute_rule.js @@ -20,6 +20,7 @@ const Utils = require('../test_lib/utils.js'); 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'); @@ -957,5 +958,24 @@ contract('TokenHolder::executeRule', async () => { (await tokenHolder.sessionKeys.call(sessionPublicKey1)).nonce.eqn(1), ); }); +}); + + 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"); + }); }); }); diff --git a/test/user_wallet_factory/create_user_wallet.js b/test/user_wallet_factory/create_user_wallet.js index 8de056a..cad48e2 100644 --- a/test/user_wallet_factory/create_user_wallet.js +++ b/test/user_wallet_factory/create_user_wallet.js @@ -330,4 +330,16 @@ 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"); + + }); + }); }); From c8d155184adba05cef68423241a66aa164662da4 Mon Sep 17 00:00:00 2001 From: Gulshan Vasnani Date: Thu, 28 Mar 2019 12:09:07 +0530 Subject: [PATCH 2/2] Fixed eslint issues --- test/test_lib/utils.js | 16 ++++++++-------- test/token_holder/execute_rule.js | 12 ++++++------ test/user_wallet_factory/create_user_wallet.js | 6 ++---- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/test/test_lib/utils.js b/test/test_lib/utils.js index 04b0539..cd35322 100644 --- a/test/test_lib/utils.js +++ b/test/test_lib/utils.js @@ -171,15 +171,16 @@ module.exports = { const contract = artifacts.require(contractName); let methodConcat = methodName.concat('('); - let input, abiMethod; + let input; + let abiMethod; - for(let i = 0; i < contract.abi.length; i++) { + 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 ++) { + if (abiMethod.name === methodName) { + for (let j = 0; j < abiMethod.inputs.length - 1; j += 1) { input = abiMethod.inputs[j].type; - methodConcat = methodConcat.concat(input,','); - } + methodConcat = methodConcat.concat(input, ','); + } input = abiMethod.inputs[abiMethod.inputs.length - 1].type; methodConcat += input; } @@ -189,7 +190,6 @@ module.exports = { const expectedPrefix = web3.utils.soliditySha3(methodConcat).substring(0, 10); assert.strictEqual(expectedPrefix, callPrefix, `Expected ${methodName} callprefix is ${callPrefix} but got ${expectedPrefix}`); - }, getParamFromTxEvent: ( @@ -219,5 +219,5 @@ module.exports = { assert(typeof param !== 'undefined'); return param; - } + }, }; diff --git a/test/token_holder/execute_rule.js b/test/token_holder/execute_rule.js index a4275d7..85b92ef 100644 --- a/test/token_holder/execute_rule.js +++ b/test/token_holder/execute_rule.js @@ -20,6 +20,7 @@ const Utils = require('../test_lib/utils.js'); 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'); @@ -958,24 +959,23 @@ contract('TokenHolder::executeRule', async () => { (await tokenHolder.sessionKeys.call(sessionPublicKey1)).nonce.eqn(1), ); }); -}); + }); 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"; + const methodName = 'executeRule'; - Utils.verifyCallPrefixConstant(methodName, tokenHolderExecuteRuleCallPrefix, "TokenHolder"); + 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"; + const methodName = 'executeRedemption'; - Utils.verifyCallPrefixConstant(methodName, tokenHolderExecuteRuleCallPrefix, "TokenHolder"); + Utils.verifyCallPrefixConstant(methodName, tokenHolderExecuteRuleCallPrefix, 'TokenHolder'); }); }); }); diff --git a/test/user_wallet_factory/create_user_wallet.js b/test/user_wallet_factory/create_user_wallet.js index cad48e2..2faca65 100644 --- a/test/user_wallet_factory/create_user_wallet.js +++ b/test/user_wallet_factory/create_user_wallet.js @@ -333,13 +333,11 @@ 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"); + const methodName = 'setup'; + Utils.verifyCallPrefixConstant(methodName, tokenHolderSetupCallPrefix, 'TokenHolder'); }); }); });