diff --git a/test/test_lib/utils.js b/test/test_lib/utils.js index 4c4149a..cd35322 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; + 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, ) => { diff --git a/test/token_holder/execute_rule.js b/test/token_holder/execute_rule.js index 53d49eb..85b92ef 100644 --- a/test/token_holder/execute_rule.js +++ b/test/token_holder/execute_rule.js @@ -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'; @@ -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'); + }); + }); }); diff --git a/test/user_wallet_factory/create_user_wallet.js b/test/user_wallet_factory/create_user_wallet.js index 8de056a..2faca65 100644 --- a/test/user_wallet_factory/create_user_wallet.js +++ b/test/user_wallet_factory/create_user_wallet.js @@ -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'); + }); + }); });