diff --git a/test/u_single_trade_volume_restriction.js b/test/u_single_trade_volume_restriction.js index 7b8dc6c10..b9a8ccb52 100644 --- a/test/u_single_trade_volume_restriction.js +++ b/test/u_single_trade_volume_restriction.js @@ -1,13 +1,15 @@ import latestTime from './helpers/latestTime'; import { duration, ensureException, promisifyLogWatch, latestBlock } from './helpers/utils'; import takeSnapshot, { increaseTime, revertToSnapshot } from './helpers/time'; +import { encodeProxyCall } from './helpers/encodeCall'; const PolymathRegistry = artifacts.require('./PolymathRegistry.sol') const ModuleRegistry = artifacts.require('./ModuleRegistry.sol'); const SecurityToken = artifacts.require('./SecurityToken.sol'); const SecurityTokenRegistry = artifacts.require('./SecurityTokenRegistry.sol'); -const TickerRegistry = artifacts.require('./TickerRegistry.sol'); -const STVersion = artifacts.require('./STVersionProxy001.sol'); +const SecurityTokenRegistryProxy = artifacts.require('./SecurityTokenRegistryProxy.sol'); +const FeatureRegistry = artifacts.require('./FeatureRegistry.sol'); +const STFactory = artifacts.require('./STFactory.sol'); const GeneralPermissionManagerFactory = artifacts.require('./GeneralPermissionManagerFactory.sol'); const GeneralTransferManagerFactory = artifacts.require('./GeneralTransferManagerFactory.sol'); const GeneralTransferManager = artifacts.require('./GeneralTransferManager'); @@ -43,6 +45,7 @@ contract('SingleTradeVolumeRestrictionManager', accounts => { let message = "Transaction Should Fail!"; // Contract Instance Declaration + let I_SecurityTokenRegistryProxy let I_GeneralPermissionManagerFactory; let I_GeneralTransferManagerFactory; let I_GeneralPermissionManager; @@ -53,9 +56,10 @@ contract('SingleTradeVolumeRestrictionManager', accounts => { let P_SingleTradeVolumeRestrictionManager; let I_SingleTradeVolumeRestrictionPercentageManager; let I_ModuleRegistry; - let I_TickerRegistry; + let I_FeatureRegistry; let I_SecurityTokenRegistry; - let I_STVersion; + let I_STRProxied; + let I_STFactory; let I_SecurityToken; let I_PolyToken; let I_PolymathRegistry; @@ -74,157 +78,153 @@ contract('SingleTradeVolumeRestrictionManager', accounts => { const stoKey = 3; // Initial fee for ticker registry and security token registry - const initRegFee = 250 * Math.pow(10, 18); + const initRegFee = web3.utils.toWei("250"); before(async() => { - // Accounts setup - account_polymath = accounts[0]; - account_issuer = accounts[1]; + // Accounts setup + account_polymath = accounts[0]; + account_issuer = accounts[1]; - token_owner = account_issuer; + token_owner = account_issuer; - account_investor1 = accounts[6]; - account_investor2 = accounts[7]; - account_investor3 = accounts[8]; - account_investor4 = accounts[9]; - account_investor5 = accounts[5]; + account_investor1 = accounts[6]; + account_investor2 = accounts[7]; + account_investor3 = accounts[8]; + account_investor4 = accounts[9]; + account_investor5 = accounts[5]; - // ----------- POLYMATH NETWORK Configuration ------------ + // ----------- POLYMATH NETWORK Configuration ------------ - // Step 0: Deploy the PolymathRegistry - I_PolymathRegistry = await PolymathRegistry.new({from: account_polymath}); + // Step 0: Deploy the PolymathRegistry + I_PolymathRegistry = await PolymathRegistry.new({from: account_polymath}); - // Step 1: Deploy the token Faucet and Mint tokens for token_owner - I_PolyToken = await PolyTokenFaucet.new(); - await I_PolyToken.getTokens((10000 * Math.pow(10, 18)), token_owner); - await I_PolymathRegistry.changeAddress("PolyToken", I_PolyToken.address, {from: account_polymath}) + // Step 1: Deploy the token Faucet and Mint tokens for token_owner + I_PolyToken = await PolyTokenFaucet.new(); + await I_PolyToken.getTokens((10000 * Math.pow(10, 18)), token_owner); + await I_PolymathRegistry.changeAddress("PolyToken", I_PolyToken.address, {from: account_polymath}) - // STEP 2: Deploy the ModuleRegistry - - I_ModuleRegistry = await ModuleRegistry.new(I_PolymathRegistry.address, {from:account_polymath}); - await I_PolymathRegistry.changeAddress("ModuleRegistry", I_ModuleRegistry.address, {from: account_polymath}); - - assert.notEqual( - I_ModuleRegistry.address.valueOf(), - "0x0000000000000000000000000000000000000000", - "ModuleRegistry contract was not deployed" - ); - - // STEP 2: Deploy the GeneralTransferManagerFactory - - I_GeneralTransferManagerFactory = await GeneralTransferManagerFactory.new(I_PolyToken.address, 0, 0, 0, {from:account_polymath}); - - assert.notEqual( - I_GeneralTransferManagerFactory.address.valueOf(), - "0x0000000000000000000000000000000000000000", - "GeneralTransferManagerFactory contract was not deployed" - ); + // STEP 2: Deploy the ModuleRegistry + I_ModuleRegistry = await ModuleRegistry.new(I_PolymathRegistry.address, {from:account_polymath}); + await I_PolymathRegistry.changeAddress("ModuleRegistry", I_ModuleRegistry.address, {from: account_polymath}); + assert.notEqual( + I_ModuleRegistry.address.valueOf(), + "0x0000000000000000000000000000000000000000", + "ModuleRegistry contract was not deployed" + ); - // STEP 3: Deploy the GeneralPermissionManagerFactory + // STEP 2: Deploy the GeneralTransferManagerFactory - I_GeneralPermissionManagerFactory = await GeneralPermissionManagerFactory.new(I_PolyToken.address, 0, 0, 0, {from:account_polymath}); + I_GeneralTransferManagerFactory = await GeneralTransferManagerFactory.new(I_PolyToken.address, 0, 0, 0, {from:account_polymath}); - assert.notEqual( - I_GeneralPermissionManagerFactory.address.valueOf(), - "0x0000000000000000000000000000000000000000", - "GeneralDelegateManagerFactory contract was not deployed" - ); + assert.notEqual( + I_GeneralTransferManagerFactory.address.valueOf(), + "0x0000000000000000000000000000000000000000", + "GeneralTransferManagerFactory contract was not deployed" + ); - // STEP 4: Deploy the SingleTradeVolumeRestrictionManagerFactory - I_SingleTradeVolumeRestrictionManagerFactory = await SingleTradeVolumeRestrictionManagerFactory.new(I_PolyToken.address, 0, 0, 0, {from: account_polymath}); + // STEP 3: Deploy the GeneralDelegateManagerFactoryFactory - assert.notEqual( - I_SingleTradeVolumeRestrictionManagerFactory.address.valueOf(), - "0x0000000000000000000000000000000000000000", - "SingleTradeVolumeRestrictionManagerFactory contract was not deployed" - ); + I_GeneralPermissionManagerFactory = await GeneralPermissionManagerFactory.new(I_PolyToken.address, 0, 0, 0, {from:account_polymath}); + assert.notEqual( + I_GeneralPermissionManagerFactory.address.valueOf(), + "0x0000000000000000000000000000000000000000", + "GeneralDelegateManagerFactory contract was not deployed" + ); - P_SingleTradeVolumeRestrictionManagerFactory = await SingleTradeVolumeRestrictionManagerFactory.new(I_PolyToken.address, web3.utils.toWei("500", "ether"), 0, 0, {from:account_polymath}); - assert.notEqual( - P_SingleTradeVolumeRestrictionManagerFactory.address.valueOf(), - "0x0000000000000000000000000000000000000000", - "SingleTradeVolumeRestrictionManagerFactory contract was not deployed" - ); - - // STEP 5: Register the Modules with the ModuleRegistry contract + // STEP 4: Deploy the SingleTradeVolumeRestrictionManagerFactory + I_SingleTradeVolumeRestrictionManagerFactory = await SingleTradeVolumeRestrictionManagerFactory.new(I_PolyToken.address, 0, 0, 0, {from: account_polymath}); - // (A) : Register the GeneralTransferManagerFactory - await I_ModuleRegistry.registerModule(I_GeneralTransferManagerFactory.address, { from: account_polymath }); - await I_ModuleRegistry.verifyModule(I_GeneralTransferManagerFactory.address, true, { from: account_polymath }); + assert.notEqual( + I_SingleTradeVolumeRestrictionManagerFactory.address.valueOf(), + "0x0000000000000000000000000000000000000000", + "SingleTradeVolumeRestrictionManagerFactory contract was not deployed" + ); + P_SingleTradeVolumeRestrictionManagerFactory = await SingleTradeVolumeRestrictionManagerFactory.new(I_PolyToken.address, web3.utils.toWei("500", "ether"), 0, 0, {from:account_polymath}); + assert.notEqual( + P_SingleTradeVolumeRestrictionManagerFactory.address.valueOf(), + "0x0000000000000000000000000000000000000000", + "SingleTradeVolumeRestrictionManagerFactory contract was not deployed" + ); - // (B) : Register the GeneralDelegateManagerFactory - await I_ModuleRegistry.registerModule(I_GeneralPermissionManagerFactory.address, { from: account_polymath }); - await I_ModuleRegistry.verifyModule(I_GeneralPermissionManagerFactory.address, true, { from: account_polymath }); + // STEP 5: Register the Modules with the ModuleRegistry contract - // (C) : Register SingleTradeVolumeRestrictionManagerFactory - await I_ModuleRegistry.registerModule(I_SingleTradeVolumeRestrictionManagerFactory.address, { from: account_polymath }); - await I_ModuleRegistry.verifyModule(I_SingleTradeVolumeRestrictionManagerFactory.address, true, { from: account_polymath }); + // (A) : Register the GeneralTransferManagerFactory + await I_ModuleRegistry.registerModule(I_GeneralTransferManagerFactory.address, { from: account_polymath }); + await I_ModuleRegistry.verifyModule(I_GeneralTransferManagerFactory.address, true, { from: account_polymath }); - await I_ModuleRegistry.registerModule(P_SingleTradeVolumeRestrictionManagerFactory.address, { from: account_polymath }); - await I_ModuleRegistry.verifyModule(P_SingleTradeVolumeRestrictionManagerFactory.address, true, { from: account_polymath }); + // (B) : Register the GeneralDelegateManagerFactory + await I_ModuleRegistry.registerModule(I_GeneralPermissionManagerFactory.address, { from: account_polymath }); + await I_ModuleRegistry.verifyModule(I_GeneralPermissionManagerFactory.address, true, { from: account_polymath }); - // Step 6: Deploy the TickerRegistry - I_TickerRegistry = await TickerRegistry.new(I_PolymathRegistry.address, initRegFee, { from: account_polymath }); - await I_PolymathRegistry.changeAddress("TickerRegistry", I_TickerRegistry.address, {from: account_polymath}); + // (C) : Register SingleTradeVolumeRestrictionManagerFactory + await I_ModuleRegistry.registerModule(I_SingleTradeVolumeRestrictionManagerFactory.address, { from: account_polymath }); + await I_ModuleRegistry.verifyModule(I_SingleTradeVolumeRestrictionManagerFactory.address, true, { from: account_polymath }); + await I_ModuleRegistry.registerModule(P_SingleTradeVolumeRestrictionManagerFactory.address, { from: account_polymath }); + await I_ModuleRegistry.verifyModule(P_SingleTradeVolumeRestrictionManagerFactory.address, true, { from: account_polymath }); - assert.notEqual( - I_TickerRegistry.address.valueOf(), - "0x0000000000000000000000000000000000000000", - "TickerRegistry contract was not deployed", - ); + // Step 7: Deploy the STFactory contract - // Step 7: Deploy the STversionProxy contract + I_STFactory = await STFactory.new(I_GeneralTransferManagerFactory.address); - I_STVersion = await STVersion.new(I_GeneralTransferManagerFactory.address); + assert.notEqual( + I_STFactory.address.valueOf(), + "0x0000000000000000000000000000000000000000", + "STFactory contract was not deployed", + ); - assert.notEqual( - I_STVersion.address.valueOf(), - "0x0000000000000000000000000000000000000000", - "STVersion contract was not deployed", - ); + // Step 9: Deploy the SecurityTokenRegistry - // Step 8: Deploy the SecurityTokenRegistry + I_SecurityTokenRegistry = await SecurityTokenRegistry.new({from: account_polymath }); - I_SecurityTokenRegistry = await SecurityTokenRegistry.new( - I_PolymathRegistry.address, - I_STVersion.address, - initRegFee, - { - from: account_polymath - }); - await I_PolymathRegistry.changeAddress("SecurityTokenRegistry", I_SecurityTokenRegistry.address, {from: account_polymath}); - - assert.notEqual( - I_SecurityTokenRegistry.address.valueOf(), - "0x0000000000000000000000000000000000000000", - "SecurityTokenRegistry contract was not deployed", - ); + assert.notEqual( + I_SecurityTokenRegistry.address.valueOf(), + "0x0000000000000000000000000000000000000000", + "SecurityTokenRegistry contract was not deployed", + ); + + // Step 10: update the registries addresses from the PolymathRegistry contract + I_SecurityTokenRegistryProxy = await SecurityTokenRegistryProxy.new({from: account_polymath}); + let bytesProxy = encodeProxyCall([I_PolymathRegistry.address, I_STFactory.address, initRegFee, initRegFee, I_PolyToken.address, account_polymath]); + await I_SecurityTokenRegistryProxy.upgradeToAndCall("1.0.0", I_SecurityTokenRegistry.address, bytesProxy, {from: account_polymath}); + I_STRProxied = await SecurityTokenRegistry.at(I_SecurityTokenRegistryProxy.address); + // Step 10: Deploy the FeatureRegistry + + I_FeatureRegistry = await FeatureRegistry.new( + I_PolymathRegistry.address, + { + from: account_polymath + }); + await I_PolymathRegistry.changeAddress("FeatureRegistry", I_FeatureRegistry.address, {from: account_polymath}); - // Step 10: update the registries addresses from the PolymathRegistry contract - await I_SecurityTokenRegistry.updateFromRegistry({from: account_polymath}); - await I_ModuleRegistry.updateFromRegistry({from: account_polymath}); - await I_TickerRegistry.updateFromRegistry({from: account_polymath}); + assert.notEqual( + I_FeatureRegistry.address.valueOf(), + "0x0000000000000000000000000000000000000000", + "FeatureRegistry contract was not deployed", + ); + // Step 11: update the registries addresses from the PolymathRegistry contract + await I_PolymathRegistry.changeAddress("SecurityTokenRegistry", I_STRProxied.address, {from: account_polymath}); + await I_ModuleRegistry.updateFromRegistry({from: account_polymath}); }) describe("Generate the SecurityToken", async () => { it("Should register the ticker before the generation of the security token", async () => { - await I_PolyToken.approve(I_TickerRegistry.address, initRegFee, { from: token_owner }); - let tx = await I_TickerRegistry.registerTicker(token_owner, symbol, contact, swarmHash, { from : token_owner }); + await I_PolyToken.approve(I_STRProxied.address, initRegFee, { from: token_owner }); + let tx = await I_STRProxied.registerTicker(token_owner, symbol, contact, { from : token_owner }); assert.equal(tx.logs[0].args._owner, token_owner); - assert.equal(tx.logs[0].args._symbol, symbol.toUpperCase()); + assert.equal(tx.logs[0].args._ticker, symbol.toUpperCase()); }); it("Should generate the new security token with the same symbol as registered above", async () => { - await I_PolyToken.approve(I_SecurityTokenRegistry.address, initRegFee, { from: token_owner }); + await I_PolyToken.approve(I_STRProxied.address, initRegFee, { from: token_owner }); let _blockNo = latestBlock(); - let tx = await I_SecurityTokenRegistry.generateSecurityToken(name, symbol, tokenDetails, false, { from: token_owner, gas: 60000000 }); + let tx = await I_STRProxied.generateSecurityToken(name, symbol, tokenDetails, false, { from: token_owner, gas: 60000000 }); // Verify the successful generation of the security token assert.equal(tx.logs[1].args._ticker, symbol.toUpperCase(), "SecurityToken doesn't get deployed"); @@ -235,12 +235,16 @@ contract('SingleTradeVolumeRestrictionManager', accounts => { // Verify that GeneralTransferManager module get added successfully or not assert.equal(log.args._type.toNumber(), 2); - assert.equal(web3.utils.toUtf8(log.args._name), "GeneralTransferManager"); + assert.equal( + web3.utils.toAscii(log.args._name) + .replace(/\u0000/g, ''), + "GeneralTransferManager" + ); }); it("Should intialize the auto attached modules", async () => { let moduleData = await I_SecurityToken.modules(2, 0); - I_GeneralTransferManager = GeneralTransferManager.at(moduleData[1]); + I_GeneralTransferManager = GeneralTransferManager.at(moduleData); assert.notEqual( I_GeneralTransferManager.address.valueOf(),