diff --git a/ethereum/contracts/icco/contributor/Contributor.sol b/ethereum/contracts/icco/contributor/Contributor.sol index e67eb02f..b78a725a 100644 --- a/ethereum/contracts/icco/contributor/Contributor.sol +++ b/ethereum/contracts/icco/contributor/Contributor.sol @@ -510,7 +510,9 @@ contract Contributor is ContributorGovernance, ContributorEvents, ReentrancyGuar address tokenAddress = address(uint160(uint256(tokenAddressBytes))); + /// grab the amount to refund the user uint256 thisRefundContribution = getSaleContribution(saleId, tokenIndex, msg.sender); + /// refund tokens SafeERC20.safeTransfer( IERC20(tokenAddress), diff --git a/ethereum/test/icco.js b/ethereum/test/icco.js index f48cd030..2489e0f8 100644 --- a/ethereum/test/icco.js +++ b/ethereum/test/icco.js @@ -7,41 +7,24 @@ const TokenImplementation = artifacts.require("TokenImplementation"); const TokenSaleConductor = artifacts.require("TokenSaleConductor"); const TokenSaleContributor = artifacts.require("TokenSaleContributor"); -const MockConductorImplementation = artifacts.require( - "MockConductorImplementation" -); -const MockContributorImplementation = artifacts.require( - "MockContributorImplementation" -); +const MockConductorImplementation = artifacts.require("MockConductorImplementation"); +const MockContributorImplementation = artifacts.require("MockContributorImplementation"); const ICCOStructs = artifacts.require("ICCOStructs"); const ConductorImplementation = artifacts.require("ConductorImplementation"); -const ContributorImplementation = artifacts.require( - "ContributorImplementation" -); +const ContributorImplementation = artifacts.require("ContributorImplementation"); // library upgrade test const MockICCOStructs = artifacts.require("MockICCOStructs"); -const MockConductorImplementation2 = artifacts.require( - "MockConductorImplementation2" -); -const MockContributorImplementation2 = artifacts.require( - "MockContributorImplementation2" -); +const MockConductorImplementation2 = artifacts.require("MockConductorImplementation2"); +const MockContributorImplementation2 = artifacts.require("MockContributorImplementation2"); -const testSigner1PK = - "cfb12303a19cde580bb4dd771639b0d26bc68353645571a8cff516ab2ee113a0"; -const kycSignerPK = - "b0057716d5917badaf911b193b12b910811c1497b5bada8d7711f758981c3773"; +const testSigner1PK = "cfb12303a19cde580bb4dd771639b0d26bc68353645571a8cff516ab2ee113a0"; +const kycSignerPK = "b0057716d5917badaf911b193b12b910811c1497b5bada8d7711f758981c3773"; -const WormholeImplementationFullABI = jsonfile.readFileSync( - "wormhole/ethereum/build/contracts/Implementation.json" -).abi; -const ConductorImplementationFullABI = jsonfile.readFileSync( - "build/contracts/ConductorImplementation.json" -).abi; -const ContributorImplementationFullABI = jsonfile.readFileSync( - "build/contracts/ContributorImplementation.json" -).abi; +const WormholeImplementationFullABI = jsonfile.readFileSync("wormhole/ethereum/build/contracts/Implementation.json") + .abi; +const ConductorImplementationFullABI = jsonfile.readFileSync("build/contracts/ConductorImplementation.json").abi; +const ContributorImplementationFullABI = jsonfile.readFileSync("build/contracts/ContributorImplementation.json").abi; // global variables const SOLANA_CHAIN_ID = "1"; @@ -49,28 +32,20 @@ const TEST_CHAIN_ID = "2"; const GAS_LIMIT = "3000000"; const ethereumRootPath = `${__dirname}/..`; -const config = require(`${ethereumRootPath}/icco_deployment_config.js`) - .development; +const config = require(`${ethereumRootPath}/icco_deployment_config.js`).development; contract("ICCO", function(accounts) { - const WORMHOLE = new web3.eth.Contract( - WormholeImplementationFullABI, - config.wormhole - ); - const CONDUCTOR_BYTES32_ADDRESS = - "0x000000000000000000000000" + TokenSaleConductor.address.substr(2); + const WORMHOLE = new web3.eth.Contract(WormholeImplementationFullABI, config.wormhole); + const CONDUCTOR_BYTES32_ADDRESS = "0x000000000000000000000000" + TokenSaleConductor.address.substr(2); const KYC_AUTHORITY = "0x1dF62f291b2E969fB0849d99D9Ce41e2F137006e"; const WORMHOLE_FEE = 1000; it("should set wormhole fee", async function() { - console.log( - "\n -------------------------- Set Wormhole Messaging Fee --------------------------" - ); + console.log("\n -------------------------- Set Wormhole Messaging Fee --------------------------"); const timestamp = 1000; const nonce = 1001; const emitterChainId = "1"; - const emitterAddress = - "0x0000000000000000000000000000000000000000000000000000000000000004"; + const emitterAddress = "0x0000000000000000000000000000000000000000000000000000000000000004"; const newMessageFee = WORMHOLE_FEE; data = [ @@ -87,17 +62,7 @@ contract("ICCO", function(accounts) { web3.eth.abi.encodeParameter("uint256", newMessageFee).substring(2), ].join(""); - const vm = await signAndEncodeVM( - timestamp, - nonce, - emitterChainId, - emitterAddress, - 0, - data, - [testSigner1PK], - 0, - 2 - ); + const vm = await signAndEncodeVM(timestamp, nonce, emitterChainId, emitterAddress, 0, data, [testSigner1PK], 0, 2); let before = await WORMHOLE.methods.messageFee().call(); @@ -114,13 +79,8 @@ contract("ICCO", function(accounts) { }); it("conductor should be initialized with the correct values", async function() { - console.log( - "\n -------------------------- Initialization and Upgrades --------------------------" - ); - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + console.log("\n -------------------------- Initialization and Upgrades --------------------------"); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); // chain id const chainId = await initialized.methods.chainId().call(); @@ -136,27 +96,17 @@ contract("ICCO", function(accounts) { }); it("contributor should be initialized with the correct values", async function() { - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); // chain id const chainId = await initialized.methods.chainId().call(); assert.equal(chainId, TEST_CHAIN_ID); // conductor - const conductorChainId = await initialized.methods - .conductorChainId() - .call(); + const conductorChainId = await initialized.methods.conductorChainId().call(); assert.equal(conductorChainId, TEST_CHAIN_ID); - const conductorContract = await initialized.methods - .conductorContract() - .call(); - assert.equal( - conductorContract.substr(26).toLowerCase(), - TokenSaleConductor.address.substr(2).toLowerCase() - ); + const conductorContract = await initialized.methods.conductorContract().call(); + assert.equal(conductorContract.substr(26).toLowerCase(), TokenSaleConductor.address.substr(2).toLowerCase()); // wormhole const WORMHOLE = await initialized.methods.wormhole().call(); @@ -173,30 +123,20 @@ contract("ICCO", function(accounts) { "0x000000000000000000000000" + TokenSaleContributor.address.substr(2) ); - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); - let before = await initialized.methods - .contributorContracts(TEST_CHAIN_ID) - .call(); + let before = await initialized.methods.contributorContracts(TEST_CHAIN_ID).call(); - assert.equal( - before, - "0x0000000000000000000000000000000000000000000000000000000000000000" - ); + assert.equal(before, "0x0000000000000000000000000000000000000000000000000000000000000000"); // attempt to register a chain from non-owner account let failed = false; try { - await initialized.methods - .registerChain(TEST_CHAIN_ID, contributorAddress) - .send({ - value: 0, - from: accounts[1], - gasLimit: GAS_LIMIT, - }); + await initialized.methods.registerChain(TEST_CHAIN_ID, contributorAddress).send({ + value: 0, + from: accounts[1], + gasLimit: GAS_LIMIT, + }); } catch (e) { assert.equal( e.message, @@ -207,33 +147,24 @@ contract("ICCO", function(accounts) { assert.ok(failed); - const tx = await initialized.methods - .registerChain(TEST_CHAIN_ID, contributorAddress) - .send({ - value: 0, - from: accounts[0], - gasLimit: GAS_LIMIT, - }); + const tx = await initialized.methods.registerChain(TEST_CHAIN_ID, contributorAddress).send({ + value: 0, + from: accounts[0], + gasLimit: GAS_LIMIT, + }); - let after = await initialized.methods - .contributorContracts(TEST_CHAIN_ID) - .call(); + let after = await initialized.methods.contributorContracts(TEST_CHAIN_ID).call(); - assert.equal( - after.substr(26).toLowerCase(), - TokenSaleContributor.address.substr(2).toLowerCase() - ); + assert.equal(after.substr(26).toLowerCase(), TokenSaleContributor.address.substr(2).toLowerCase()); // attempt to register a contributor a second time failed = false; try { - await initialized.methods - .registerChain(TEST_CHAIN_ID, contributorAddress) - .send({ - value: 0, - from: accounts[0], - gasLimit: GAS_LIMIT, - }); + await initialized.methods.registerChain(TEST_CHAIN_ID, contributorAddress).send({ + value: 0, + from: accounts[0], + gasLimit: GAS_LIMIT, + }); } catch (e) { assert.equal( e.message, @@ -244,10 +175,7 @@ contract("ICCO", function(accounts) { }); it("conductor should accept a valid upgrade", async function() { - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); // deploy mock contracts and link ICCOStructs library const structs = await ICCOStructs.new(); @@ -278,18 +206,13 @@ contract("ICCO", function(accounts) { "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc" ); - assert.equal( - before.toLowerCase(), - ConductorImplementation.address.toLowerCase() - ); + assert.equal(before.toLowerCase(), ConductorImplementation.address.toLowerCase()); - const upgradeTx = await initialized.methods - .upgrade(TEST_CHAIN_ID, mock.address) - .send({ - value: 0, - from: accounts[0], - gasLimit: GAS_LIMIT, - }); + const upgradeTx = await initialized.methods.upgrade(TEST_CHAIN_ID, mock.address).send({ + value: 0, + from: accounts[0], + gasLimit: GAS_LIMIT, + }); let after = await web3.eth.getStorageAt( TokenSaleConductor.address, @@ -301,29 +224,18 @@ contract("ICCO", function(accounts) { // confirm that the ContractUpgraded event is emitted let eventOutput = upgradeTx["events"]["ContractUpgraded"]["returnValues"]; - assert.equal( - eventOutput["oldContract"].toLowerCase(), - before.toLowerCase() - ); + assert.equal(eventOutput["oldContract"].toLowerCase(), before.toLowerCase()); assert.equal(eventOutput["newContract"].toLowerCase(), after.toLowerCase()); - const mockImpl = new web3.eth.Contract( - MockConductorImplementation.abi, - TokenSaleConductor.address - ); + const mockImpl = new web3.eth.Contract(MockConductorImplementation.abi, TokenSaleConductor.address); - let isUpgraded = await mockImpl.methods - .testNewImplementationActive() - .call(); + let isUpgraded = await mockImpl.methods.testNewImplementationActive().call(); assert.ok(isUpgraded); }); it("contributor should accept a valid upgrade", async function() { - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); // deploy mock contracts and link ICCOStructs library const structs = await ICCOStructs.new(); @@ -353,18 +265,13 @@ contract("ICCO", function(accounts) { "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc" ); - assert.equal( - before.toLowerCase(), - ContributorImplementation.address.toLowerCase() - ); + assert.equal(before.toLowerCase(), ContributorImplementation.address.toLowerCase()); - const upgradeTx = await initialized.methods - .upgrade(TEST_CHAIN_ID, mock.address) - .send({ - value: 0, - from: accounts[0], - gasLimit: GAS_LIMIT, - }); + const upgradeTx = await initialized.methods.upgrade(TEST_CHAIN_ID, mock.address).send({ + value: 0, + from: accounts[0], + gasLimit: GAS_LIMIT, + }); let after = await web3.eth.getStorageAt( TokenSaleContributor.address, @@ -376,20 +283,12 @@ contract("ICCO", function(accounts) { // confirm that the ContractUpgraded event is emitted let eventOutput = upgradeTx["events"]["ContractUpgraded"]["returnValues"]; - assert.equal( - eventOutput["oldContract"].toLowerCase(), - before.toLowerCase() - ); + assert.equal(eventOutput["oldContract"].toLowerCase(), before.toLowerCase()); assert.equal(eventOutput["newContract"].toLowerCase(), after.toLowerCase()); - const mockImpl = new web3.eth.Contract( - MockContributorImplementation.abi, - TokenSaleContributor.address - ); + const mockImpl = new web3.eth.Contract(MockContributorImplementation.abi, TokenSaleContributor.address); - let isUpgraded = await mockImpl.methods - .testNewImplementationActive() - .call(); + let isUpgraded = await mockImpl.methods.testNewImplementationActive().call(); assert.ok(isUpgraded); }); @@ -399,14 +298,8 @@ contract("ICCO", function(accounts) { const initializedConsistencyLevel = config.consistencyLevel; const updatedConsistencyLevel = "1"; - const contributorContract = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); - const conductorContract = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const contributorContract = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); + const conductorContract = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); // update the consistency level const contributorTx = await contributorContract.methods @@ -426,61 +319,46 @@ contract("ICCO", function(accounts) { }); // check getters after the action - const contributorConsistencyLevelAfter = await contributorContract.methods - .consistencyLevel() - .call(); - const conductorConsistencyLevelAfter = await conductorContract.methods - .consistencyLevel() - .call(); + const contributorConsistencyLevelAfter = await contributorContract.methods.consistencyLevel().call(); + const conductorConsistencyLevelAfter = await conductorContract.methods.consistencyLevel().call(); assert.equal(contributorConsistencyLevelAfter, updatedConsistencyLevel); assert.equal(conductorConsistencyLevelAfter, updatedConsistencyLevel); // confirm that the ConsistencyLevelUpdate event is emitted for contributor - let contributorEventOutput = - contributorTx["events"]["ConsistencyLevelUpdated"]["returnValues"]; + let contributorEventOutput = contributorTx["events"]["ConsistencyLevelUpdated"]["returnValues"]; - assert.equal( - contributorEventOutput["oldLevel"], - initializedConsistencyLevel - ); + assert.equal(contributorEventOutput["oldLevel"], initializedConsistencyLevel); assert.equal(contributorEventOutput["newLevel"], updatedConsistencyLevel); // confirm that the ConsistencyLevelUpdate event is emitted for conductor - let conductorEventOutput = - conductorTx["events"]["ConsistencyLevelUpdated"]["returnValues"]; + let conductorEventOutput = conductorTx["events"]["ConsistencyLevelUpdated"]["returnValues"]; assert.equal(conductorEventOutput["oldLevel"], initializedConsistencyLevel); assert.equal(conductorEventOutput["newLevel"], updatedConsistencyLevel); // revert consistencyLevel back to initialized value // update the consistency level - await contributorContract.methods - .updateConsistencyLevel(TEST_CHAIN_ID, initializedConsistencyLevel) - .send({ - value: "0", - from: accounts[0], // contract owner - gasLimit: GAS_LIMIT, - }); + await contributorContract.methods.updateConsistencyLevel(TEST_CHAIN_ID, initializedConsistencyLevel).send({ + value: "0", + from: accounts[0], // contract owner + gasLimit: GAS_LIMIT, + }); - await conductorContract.methods - .updateConsistencyLevel(TEST_CHAIN_ID, initializedConsistencyLevel) - .send({ - value: "0", - from: accounts[0], // contract owner - gasLimit: GAS_LIMIT, - }); + await conductorContract.methods.updateConsistencyLevel(TEST_CHAIN_ID, initializedConsistencyLevel).send({ + value: "0", + from: accounts[0], // contract owner + gasLimit: GAS_LIMIT, + }); // make sure only the Contributor owner can change consistencyLevel let contributorFailed = false; try { - await contributorContract.methods - .updateConsistencyLevel(TEST_CHAIN_ID, initializedConsistencyLevel) - .send({ - value: "0", - from: accounts[1], // different account - gasLimit: GAS_LIMIT, - }); + await contributorContract.methods.updateConsistencyLevel(TEST_CHAIN_ID, initializedConsistencyLevel).send({ + value: "0", + from: accounts[1], // different account + gasLimit: GAS_LIMIT, + }); } catch (e) { assert.equal( e.message, @@ -492,13 +370,11 @@ contract("ICCO", function(accounts) { // make sure only the Conductor owner can change consistencyLevel conductorFailed = false; try { - await conductorContract.methods - .updateConsistencyLevel(TEST_CHAIN_ID, initializedConsistencyLevel) - .send({ - value: "0", - from: accounts[1], // different account - gasLimit: GAS_LIMIT, - }); + await conductorContract.methods.updateConsistencyLevel(TEST_CHAIN_ID, initializedConsistencyLevel).send({ + value: "0", + from: accounts[1], // different account + gasLimit: GAS_LIMIT, + }); } catch (e) { assert.equal( e.message, @@ -516,31 +392,21 @@ contract("ICCO", function(accounts) { const currentOwner = accounts[0]; const newOwner = accounts[1]; - const contributorContract = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); - const conductorContract = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const contributorContract = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); + const conductorContract = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); // transfer ownership - const contributorTx = await contributorContract.methods - .transferOwnership(TEST_CHAIN_ID, newOwner) - .send({ - value: "0", - from: currentOwner, // contract owner - gasLimit: GAS_LIMIT, - }); + const contributorTx = await contributorContract.methods.transferOwnership(TEST_CHAIN_ID, newOwner).send({ + value: "0", + from: currentOwner, // contract owner + gasLimit: GAS_LIMIT, + }); - const conductorTx = await conductorContract.methods - .transferOwnership(TEST_CHAIN_ID, newOwner) - .send({ - value: "0", - from: currentOwner, // contract owner - gasLimit: GAS_LIMIT, - }); + const conductorTx = await conductorContract.methods.transferOwnership(TEST_CHAIN_ID, newOwner).send({ + value: "0", + from: currentOwner, // contract owner + gasLimit: GAS_LIMIT, + }); // check getters after the action let contributorOwner = await contributorContract.methods.owner().call(); @@ -550,41 +416,25 @@ contract("ICCO", function(accounts) { assert.equal(conductorOwner, newOwner); // confirm that the ConsistencyLevelUpdate event is emitted for contributor - let contributorEventOutput = - contributorTx["events"]["OwnershipTransfered"]["returnValues"]; + let contributorEventOutput = contributorTx["events"]["OwnershipTransfered"]["returnValues"]; - assert.equal( - contributorEventOutput["oldOwner"].toLowerCase(), - currentOwner.toLowerCase() - ); - assert.equal( - contributorEventOutput["newOwner"].toLowerCase(), - newOwner.toLowerCase() - ); + assert.equal(contributorEventOutput["oldOwner"].toLowerCase(), currentOwner.toLowerCase()); + assert.equal(contributorEventOutput["newOwner"].toLowerCase(), newOwner.toLowerCase()); // confirm that the ConsistencyLevelUpdate event is emitted for conductor - let conductorEventOutput = - conductorTx["events"]["OwnershipTransfered"]["returnValues"]; + let conductorEventOutput = conductorTx["events"]["OwnershipTransfered"]["returnValues"]; - assert.equal( - conductorEventOutput["oldOwner"].toLowerCase(), - currentOwner.toLowerCase() - ); - assert.equal( - conductorEventOutput["newOwner"].toLowerCase(), - newOwner.toLowerCase() - ); + assert.equal(conductorEventOutput["oldOwner"].toLowerCase(), currentOwner.toLowerCase()); + assert.equal(conductorEventOutput["newOwner"].toLowerCase(), newOwner.toLowerCase()); // make sure only the owner can transfer ownership let contributorFailed = false; try { - await contributorContract.methods - .transferOwnership(TEST_CHAIN_ID, currentOwner) - .send({ - value: "0", - from: currentOwner, // no longer the current owner - gasLimit: GAS_LIMIT, - }); + await contributorContract.methods.transferOwnership(TEST_CHAIN_ID, currentOwner).send({ + value: "0", + from: currentOwner, // no longer the current owner + gasLimit: GAS_LIMIT, + }); } catch (e) { assert.equal( e.message, @@ -594,13 +444,11 @@ contract("ICCO", function(accounts) { } conductorFailed = false; try { - await conductorContract.methods - .transferOwnership(TEST_CHAIN_ID, currentOwner) - .send({ - value: "0", - from: currentOwner, // no longer the current owner - gasLimit: GAS_LIMIT, - }); + await conductorContract.methods.transferOwnership(TEST_CHAIN_ID, currentOwner).send({ + value: "0", + from: currentOwner, // no longer the current owner + gasLimit: GAS_LIMIT, + }); } catch (e) { assert.equal( e.message, @@ -613,21 +461,17 @@ contract("ICCO", function(accounts) { assert.ok(conductorFailed); // revert ownership back to currentOwner - await contributorContract.methods - .transferOwnership(TEST_CHAIN_ID, currentOwner) - .send({ - value: "0", - from: newOwner, - gasLimit: GAS_LIMIT, - }); + await contributorContract.methods.transferOwnership(TEST_CHAIN_ID, currentOwner).send({ + value: "0", + from: newOwner, + gasLimit: GAS_LIMIT, + }); - await conductorContract.methods - .transferOwnership(TEST_CHAIN_ID, currentOwner) - .send({ - value: "0", - from: newOwner, - gasLimit: GAS_LIMIT, - }); + await conductorContract.methods.transferOwnership(TEST_CHAIN_ID, currentOwner).send({ + value: "0", + from: newOwner, + gasLimit: GAS_LIMIT, + }); // check getters before the action contributorOwner = await contributorContract.methods.owner().call(); @@ -669,8 +513,7 @@ contract("ICCO", function(accounts) { // token to sell in ICCO SOLD_TOKEN = await TokenImplementation.new(); SOLD_TOKEN_DECIMALS = tokenDecimals; - SOLD_TOKEN_BYTES32_ADDRESS = - "0x000000000000000000000000" + SOLD_TOKEN.address.substr(2); + SOLD_TOKEN_BYTES32_ADDRESS = "0x000000000000000000000000" + SOLD_TOKEN.address.substr(2); const soldTokenName = "Sold Token"; const soldTokenSymbol = "SOLD"; @@ -722,9 +565,7 @@ contract("ICCO", function(accounts) { }); it("create a sale correctly and attest over wormhole", async function() { - console.log( - "\n -------------------------- Sale Test #1 (Successful) --------------------------" - ); + console.log("\n -------------------------- Sale Test #1 (Successful) --------------------------"); // test variables const current_block = await web3.eth.getBlock("latest"); @@ -744,10 +585,7 @@ contract("ICCO", function(accounts) { const numAcceptedSolanaTokens = "0"; const isFixedPriceSale = false; - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); await SOLD_TOKEN.approve(TokenSaleConductor.address, saleTokenAmount); @@ -770,44 +608,28 @@ contract("ICCO", function(accounts) { // create accepted tokens array const acceptedTokens = [ - [ - TEST_CHAIN_ID, - "0x000000000000000000000000" + CONTRIBUTED_TOKEN_ONE.address.substr(2), - tokenOneConversionRate, - ], - [ - TEST_CHAIN_ID, - "0x000000000000000000000000" + CONTRIBUTED_TOKEN_TWO.address.substr(2), - tokenTwoConversionRate, - ], + [TEST_CHAIN_ID, "0x000000000000000000000000" + CONTRIBUTED_TOKEN_ONE.address.substr(2), tokenOneConversionRate], + [TEST_CHAIN_ID, "0x000000000000000000000000" + CONTRIBUTED_TOKEN_TWO.address.substr(2), tokenTwoConversionRate], ]; // create the sale - const createSaleTx = await initialized.methods - .createSale(saleParams, acceptedTokens) - .send({ - value: WORMHOLE_FEE, - from: SELLER, - gasLimit: GAS_LIMIT, - }); + const createSaleTx = await initialized.methods.createSale(saleParams, acceptedTokens).send({ + value: WORMHOLE_FEE, + from: SELLER, + gasLimit: GAS_LIMIT, + }); // confirm that the EventCreateSale event was emitted - let eventCreateSale = - createSaleTx["events"]["EventCreateSale"]["returnValues"]; + let eventCreateSale = createSaleTx["events"]["EventCreateSale"]["returnValues"]; assert.equal(eventCreateSale["saleId"], SALE_ID); assert.equal(eventCreateSale["creatorAddress"], SELLER); // verify contributorWallets getter - const solanaWallet = await initialized.methods - .contributorWallets(SALE_ID, solanaChainId) - .call(); + const solanaWallet = await initialized.methods.contributorWallets(SALE_ID, solanaChainId).call(); assert.equal( solanaWallet, - web3.eth.abi.encodeParameter( - "address", - "0x" + SOLD_TOKEN_BYTES32_ADDRESS.substring(26) - ) + web3.eth.abi.encodeParameter("address", "0x" + SOLD_TOKEN_BYTES32_ADDRESS.substring(26)) ); // verify payload sent to contributor @@ -839,17 +661,12 @@ contract("ICCO", function(accounts) { // token chain assert.equal( log.payload.substr(index, 4), - web3.eth.abi - .encodeParameter("uint16", TEST_CHAIN_ID) - .substring(2 + 64 - 4) + web3.eth.abi.encodeParameter("uint16", TEST_CHAIN_ID).substring(2 + 64 - 4) ); index += 4; // token decimals - assert.equal( - parseInt(log.payload.substr(index, 2), 16), - SOLD_TOKEN_DECIMALS - ); + assert.equal(parseInt(log.payload.substr(index, 2), 16), SOLD_TOKEN_DECIMALS); index += 2; // timestamp start @@ -861,74 +678,51 @@ contract("ICCO", function(accounts) { index += 64; // accepted tokens length - assert.equal( - parseInt(log.payload.substr(index, 2), 16), - acceptedTokenLength - ); + assert.equal(parseInt(log.payload.substr(index, 2), 16), acceptedTokenLength); index += 2; // token address assert.equal( log.payload.substr(index, 64), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address).substring(2) ); index += 64; // token chain assert.equal( log.payload.substr(index, 4), - web3.eth.abi - .encodeParameter("uint16", TEST_CHAIN_ID) - .substring(2 + 64 - 4) + web3.eth.abi.encodeParameter("uint16", TEST_CHAIN_ID).substring(2 + 64 - 4) ); index += 4; // conversion rate - assert.equal( - parseInt(log.payload.substr(index, 32), 16), - parseInt(tokenOneConversionRate) - ); + assert.equal(parseInt(log.payload.substr(index, 32), 16), parseInt(tokenOneConversionRate)); index += 32; // token address assert.equal( log.payload.substr(index, 64), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address).substring(2) ); index += 64; // token chain assert.equal( log.payload.substr(index, 4), - web3.eth.abi - .encodeParameter("uint16", TEST_CHAIN_ID) - .substring(2 + 64 - 4) + web3.eth.abi.encodeParameter("uint16", TEST_CHAIN_ID).substring(2 + 64 - 4) ); index += 4; // conversion rate - assert.equal( - parseInt(log.payload.substr(index, 32), 16), - parseInt(tokenTwoConversionRate) - ); + assert.equal(parseInt(log.payload.substr(index, 32), 16), parseInt(tokenTwoConversionRate)); index += 32; // recipient of proceeds - assert.equal( - log.payload.substr(index, 64), - web3.eth.abi.encodeParameter("address", saleRecipient).substring(2) - ); + assert.equal(log.payload.substr(index, 64), web3.eth.abi.encodeParameter("address", saleRecipient).substring(2)); index += 64; // KYC authority public key - assert.equal( - log.payload.substr(index, 40), - web3.eth.abi.encodeParameter("address", KYC_AUTHORITY).substring(26) - ); + assert.equal(log.payload.substr(index, 40), web3.eth.abi.encodeParameter("address", KYC_AUTHORITY).substring(26)); index += 40; // unlock timestamp @@ -960,10 +754,7 @@ contract("ICCO", function(accounts) { const tokenTwoConversionRate = "2000000000000000000"; const saleRecipient = accounts[0]; - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); // create initSale VM const vm = await signAndEncodeVM( @@ -1003,30 +794,17 @@ contract("ICCO", function(accounts) { assert.equal(sale.unlockTimestamp, SALE_END); assert.equal( sale.acceptedTokensAddresses[TOKEN_ONE_INDEX].substring(2), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address).substring(2) ); assert.equal(sale.acceptedTokensChains[TOKEN_ONE_INDEX], TEST_CHAIN_ID); - assert.equal( - sale.acceptedTokensConversionRates[TOKEN_ONE_INDEX], - parseInt(tokenOneConversionRate) - ); + assert.equal(sale.acceptedTokensConversionRates[TOKEN_ONE_INDEX], parseInt(tokenOneConversionRate)); assert.equal( sale.acceptedTokensAddresses[TOKEN_TWO_INDEX].substring(2), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address).substring(2) ); assert.equal(sale.acceptedTokensChains[TOKEN_TWO_INDEX], TEST_CHAIN_ID); - assert.equal( - sale.acceptedTokensConversionRates[TOKEN_TWO_INDEX], - parseInt(tokenTwoConversionRate) - ); - assert.equal( - sale.recipient.substring(2), - web3.eth.abi.encodeParameter("address", saleRecipient).substring(2) - ); + assert.equal(sale.acceptedTokensConversionRates[TOKEN_TWO_INDEX], parseInt(tokenTwoConversionRate)); + assert.equal(sale.recipient.substring(2), web3.eth.abi.encodeParameter("address", saleRecipient).substring(2)); assert.equal(sale.authority.substring(2), KYC_AUTHORITY.substring(2)); assert.equal(sale.allocations[TOKEN_ONE_INDEX], 0); assert.equal(sale.allocations[TOKEN_TWO_INDEX], 0); @@ -1036,34 +814,24 @@ contract("ICCO", function(accounts) { assert.ok(!sale.isAborted); // verify getsaleAcceptedTokenInfo getter - const tokenOneInfo = await initialized.methods - .getSaleAcceptedTokenInfo(SALE_ID, TOKEN_ONE_INDEX) - .call(); - const tokenTwoInfo = await initialized.methods - .getSaleAcceptedTokenInfo(SALE_ID, TOKEN_TWO_INDEX) - .call(); + const tokenOneInfo = await initialized.methods.getSaleAcceptedTokenInfo(SALE_ID, TOKEN_ONE_INDEX).call(); + const tokenTwoInfo = await initialized.methods.getSaleAcceptedTokenInfo(SALE_ID, TOKEN_TWO_INDEX).call(); assert.equal( tokenOneInfo.tokenAddress.substring(2), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address).substring(2) ); assert.equal(tokenOneInfo.tokenChainId, TEST_CHAIN_ID); assert.equal(tokenOneInfo.conversionRate, parseInt(tokenOneConversionRate)); assert.equal( tokenTwoInfo.tokenAddress.substring(2), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address).substring(2) ); assert.equal(tokenTwoInfo.tokenChainId, TEST_CHAIN_ID); assert.equal(tokenTwoInfo.conversionRate, parseInt(tokenTwoConversionRate)); // verify getSaleTimeFrame getter - const saleTimeframe = await initialized.methods - .getSaleTimeframe(SALE_ID) - .call(); + const saleTimeframe = await initialized.methods.getSaleTimeframe(SALE_ID).call(); assert.equal(saleTimeframe.start, SALE_START); assert.equal(saleTimeframe.end, SALE_END); @@ -1077,10 +845,7 @@ contract("ICCO", function(accounts) { }); it("sale should only be initialized once in the contributor", async function() { - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); let failed = false; try { @@ -1106,34 +871,22 @@ contract("ICCO", function(accounts) { const tokenOneContributionAmount = ["5000", "5000"]; const tokenTwoContributionAmount = ["5000", "2500"]; - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); // approve contribution amounts await CONTRIBUTED_TOKEN_ONE.approve( TokenSaleContributor.address, - parseInt(tokenOneContributionAmount[0]) + - parseInt(tokenOneContributionAmount[1]), - { - from: BUYER_ONE, - } - ); - await CONTRIBUTED_TOKEN_TWO.approve( - TokenSaleContributor.address, - tokenTwoContributionAmount[0], - { - from: BUYER_TWO, - } - ); - await CONTRIBUTED_TOKEN_TWO.approve( - TokenSaleContributor.address, - tokenTwoContributionAmount[1], + parseInt(tokenOneContributionAmount[0]) + parseInt(tokenOneContributionAmount[1]), { from: BUYER_ONE, } ); + await CONTRIBUTED_TOKEN_TWO.approve(TokenSaleContributor.address, tokenTwoContributionAmount[0], { + from: BUYER_TWO, + }); + await CONTRIBUTED_TOKEN_TWO.approve(TokenSaleContributor.address, tokenTwoContributionAmount[1], { + from: BUYER_ONE, + }); // perform "kyc" and contribute to the token sale for BUYER_ONE const kycSig1 = await signContribution( @@ -1145,12 +898,7 @@ contract("ICCO", function(accounts) { kycSignerPK ); let contributeTx1 = await initialized.methods - .contribute( - SALE_ID, - TOKEN_ONE_INDEX, - parseInt(tokenOneContributionAmount[0]), - kycSig1 - ) + .contribute(SALE_ID, TOKEN_ONE_INDEX, parseInt(tokenOneContributionAmount[0]), kycSig1) .send({ from: BUYER_ONE, gasLimit: GAS_LIMIT, @@ -1165,12 +913,7 @@ contract("ICCO", function(accounts) { kycSignerPK ); await initialized.methods - .contribute( - SALE_ID, - TOKEN_ONE_INDEX, - parseInt(tokenOneContributionAmount[1]), - kycSig2 - ) + .contribute(SALE_ID, TOKEN_ONE_INDEX, parseInt(tokenOneContributionAmount[1]), kycSig2) .send({ from: BUYER_ONE, gasLimit: GAS_LIMIT, @@ -1185,12 +928,7 @@ contract("ICCO", function(accounts) { kycSignerPK ); await initialized.methods - .contribute( - SALE_ID, - TOKEN_TWO_INDEX, - parseInt(tokenTwoContributionAmount[1]), - kycSig3 - ) + .contribute(SALE_ID, TOKEN_TWO_INDEX, parseInt(tokenTwoContributionAmount[1]), kycSig3) .send({ from: BUYER_ONE, gasLimit: GAS_LIMIT, @@ -1206,26 +944,17 @@ contract("ICCO", function(accounts) { kycSignerPK ); await initialized.methods - .contribute( - SALE_ID, - TOKEN_TWO_INDEX, - parseInt(tokenTwoContributionAmount[0]), - kycSig4 - ) + .contribute(SALE_ID, TOKEN_TWO_INDEX, parseInt(tokenTwoContributionAmount[0]), kycSig4) .send({ from: BUYER_TWO, gasLimit: GAS_LIMIT, }); // confirm that the EventContribute event was emitted - let eventOutput1 = - contributeTx1["events"]["EventContribute"]["returnValues"]; + let eventOutput1 = contributeTx1["events"]["EventContribute"]["returnValues"]; assert.equal(eventOutput1["saleId"], SALE_ID); assert.equal(eventOutput1["tokenIndex"], TOKEN_ONE_INDEX); - assert.equal( - eventOutput1["amount"], - parseInt(tokenOneContributionAmount[0]) - ); + assert.equal(eventOutput1["amount"], parseInt(tokenOneContributionAmount[0])); // verify getSaleTotalContribution after contributing const totalContributionsTokenOne = await initialized.methods @@ -1237,13 +966,11 @@ contract("ICCO", function(accounts) { assert.equal( totalContributionsTokenOne, - parseInt(tokenOneContributionAmount[0]) + - parseInt(tokenOneContributionAmount[1]) + parseInt(tokenOneContributionAmount[0]) + parseInt(tokenOneContributionAmount[1]) ); assert.equal( totalContributionsTokenTwo, - parseInt(tokenTwoContributionAmount[0]) + - parseInt(tokenTwoContributionAmount[1]) + parseInt(tokenTwoContributionAmount[0]) + parseInt(tokenTwoContributionAmount[1]) ); // verify getSaleContribution @@ -1259,13 +986,9 @@ contract("ICCO", function(accounts) { assert.equal( buyerOneContributionTokenOne, - parseInt(tokenOneContributionAmount[0]) + - parseInt(tokenOneContributionAmount[1]) - ); - assert.equal( - buyerOneContributionTokenTwo, - parseInt(tokenTwoContributionAmount[1]) + parseInt(tokenOneContributionAmount[0]) + parseInt(tokenOneContributionAmount[1]) ); + assert.equal(buyerOneContributionTokenTwo, parseInt(tokenTwoContributionAmount[1])); assert.equal(buyerTwoContribution, parseInt(tokenTwoContributionAmount[0])); }); @@ -1273,18 +996,11 @@ contract("ICCO", function(accounts) { // test variables const tokenOneContributionAmount = "10000"; - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); - await CONTRIBUTED_TOKEN_ONE.approve( - TokenSaleContributor.address, - tokenOneContributionAmount, - { - from: BUYER_ONE, - } - ); + await CONTRIBUTED_TOKEN_ONE.approve(TokenSaleContributor.address, tokenOneContributionAmount, { + from: BUYER_ONE, + }); let failed = false; try { @@ -1298,12 +1014,7 @@ contract("ICCO", function(accounts) { accounts[0] ); await initialized.methods - .contribute( - SALE_ID, - TOKEN_ONE_INDEX, - parseInt(tokenOneContributionAmount), - kycSig1 - ) + .contribute(SALE_ID, TOKEN_ONE_INDEX, parseInt(tokenOneContributionAmount), kycSig1) .send({ from: BUYER_ONE, gasLimit: GAS_LIMIT, @@ -1324,10 +1035,7 @@ contract("ICCO", function(accounts) { const tokenOneContributionAmount = "10000"; const incorrect_sale_id = "42069"; - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); let failed = false; try { @@ -1340,21 +1048,13 @@ contract("ICCO", function(accounts) { kycSignerPK ); await initialized.methods - .contribute( - incorrect_sale_id, - TOKEN_ONE_INDEX, - tokenOneContributionAmount, - kycSig1 - ) + .contribute(incorrect_sale_id, TOKEN_ONE_INDEX, tokenOneContributionAmount, kycSig1) .send({ from: BUYER_TWO, gasLimit: GAS_LIMIT, }); } catch (e) { - assert.equal( - e.message, - "Returned error: VM Exception while processing transaction: revert sale not initiated" - ); + assert.equal(e.message, "Returned error: VM Exception while processing transaction: revert sale not initiated"); failed = true; } @@ -1367,10 +1067,7 @@ contract("ICCO", function(accounts) { // test variables const tokenTwoContributionAmount = "5000"; - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); let failed = false; try { @@ -1382,22 +1079,12 @@ contract("ICCO", function(accounts) { BUYER_TWO, kycSignerPK ); - await initialized.methods - .contribute( - SALE_ID, - TOKEN_TWO_INDEX, - tokenTwoContributionAmount, - kycSig1 - ) - .send({ - from: BUYER_TWO, - gasLimit: GAS_LIMIT, - }); + await initialized.methods.contribute(SALE_ID, TOKEN_TWO_INDEX, tokenTwoContributionAmount, kycSig1).send({ + from: BUYER_TWO, + gasLimit: GAS_LIMIT, + }); } catch (e) { - assert.equal( - e.message, - "Returned error: VM Exception while processing transaction: revert sale has ended" - ); + assert.equal(e.message, "Returned error: VM Exception while processing transaction: revert sale has ended"); failed = true; } @@ -1413,23 +1100,17 @@ contract("ICCO", function(accounts) { const acceptedTokenLength = 2; const payloadIdType2 = "02"; - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); // attest contributions - const attestTx = await initialized.methods - .attestContributions(SALE_ID) - .send({ - from: BUYER_ONE, - value: WORMHOLE_FEE, - gasLimit: GAS_LIMIT, - }); + const attestTx = await initialized.methods.attestContributions(SALE_ID).send({ + from: BUYER_ONE, + value: WORMHOLE_FEE, + gasLimit: GAS_LIMIT, + }); // confirm that the EventAttestContribution event was emitted - let eventOutput = - attestTx["events"]["EventAttestContribution"]["returnValues"]; + let eventOutput = attestTx["events"]["EventAttestContribution"]["returnValues"]; assert.equal(eventOutput["saleId"], SALE_ID); const log = ( @@ -1450,49 +1131,33 @@ contract("ICCO", function(accounts) { index += 64; // chain id - assert.equal( - log.payload.substr(index, 4), - web3.eth.abi.encodeParameter("uint16", 2).substring(2 + 64 - 4) - ); + assert.equal(log.payload.substr(index, 4), web3.eth.abi.encodeParameter("uint16", 2).substring(2 + 64 - 4)); index += 4; // tokens length - assert.equal( - parseInt(log.payload.substr(index, 2), 16), - acceptedTokenLength - ); + assert.equal(parseInt(log.payload.substr(index, 2), 16), acceptedTokenLength); index += 2; // token index assert.equal( log.payload.substr(index, 2), - web3.eth.abi - .encodeParameter("uint8", TOKEN_ONE_INDEX) - .substring(2 + 64 - 2) + web3.eth.abi.encodeParameter("uint8", TOKEN_ONE_INDEX).substring(2 + 64 - 2) ); index += 2; // amount - assert.equal( - parseInt(log.payload.substr(index, 64), 16), - tokenOneContributionAmount - ); + assert.equal(parseInt(log.payload.substr(index, 64), 16), tokenOneContributionAmount); index += 64; // token index assert.equal( log.payload.substr(index, 2), - web3.eth.abi - .encodeParameter("uint8", TOKEN_TWO_INDEX) - .substring(2 + 64 - 2) + web3.eth.abi.encodeParameter("uint8", TOKEN_TWO_INDEX).substring(2 + 64 - 2) ); index += 2; // amount - assert.equal( - parseInt(log.payload.substr(index, 64), 16), - tokenTwoContributionAmount - ); + assert.equal(parseInt(log.payload.substr(index, 64), 16), tokenTwoContributionAmount); index += 64; assert.equal(log.payload.length, index); @@ -1504,10 +1169,7 @@ contract("ICCO", function(accounts) { const tokenOneContributionAmount = "10000"; const tokenTwoContributionAmount = "7500"; - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); // verify saleContributionIsCollected getter before collecting contributions const isContributionOneCollectedBefore = await initialized.methods @@ -1549,19 +1211,14 @@ contract("ICCO", function(accounts) { assert.ok(isContributionTwoCollectedAfter); // verify saleContributions getter - const contributions = await initialized.methods - .saleContributions(SALE_ID) - .call(); + const contributions = await initialized.methods.saleContributions(SALE_ID).call(); assert.equal(contributions[0], tokenOneContributionAmount); assert.equal(contributions[1], tokenTwoContributionAmount); }); it("conductor should not collect contributions more than once", async function() { - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); const vm = await signAndEncodeVM( 1, @@ -1596,10 +1253,7 @@ contract("ICCO", function(accounts) { let SALE_SEALED_PAYLOAD; it("conductor should not seal a sale for a non-existent saleID", async function() { - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); let failed = false; try { @@ -1609,10 +1263,7 @@ contract("ICCO", function(accounts) { gasLimit: GAS_LIMIT, }); } catch (e) { - assert.equal( - e.message, - "Returned error: VM Exception while processing transaction: revert sale not initiated" - ); + assert.equal(e.message, "Returned error: VM Exception while processing transaction: revert sale not initiated"); failed = true; } @@ -1627,23 +1278,13 @@ contract("ICCO", function(accounts) { const expectedConductorBalanceAfter = "0"; const payloadIdType3 = "03"; - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); // balance check before sealing the sale - const actualContributorBalanceBefore = await SOLD_TOKEN.balanceOf( - TokenSaleContributor.address - ); - const actualConductorBalanceBefore = await SOLD_TOKEN.balanceOf( - TokenSaleConductor.address - ); + const actualContributorBalanceBefore = await SOLD_TOKEN.balanceOf(TokenSaleContributor.address); + const actualConductorBalanceBefore = await SOLD_TOKEN.balanceOf(TokenSaleConductor.address); - assert.equal( - actualContributorBalanceBefore, - expectedContributorBalanceBefore - ); + assert.equal(actualContributorBalanceBefore, expectedContributorBalanceBefore); assert.equal(actualConductorBalanceBefore, expectedConductorBalanceBefore); // verify sealSealed flag in sales @@ -1663,17 +1304,10 @@ contract("ICCO", function(accounts) { assert.equal(eventSeal["saleId"], SALE_ID); // balance check after sealing the sale - const actualContributorBalanceAfter = await SOLD_TOKEN.balanceOf( - TokenSaleContributor.address - ); - const actualConductorBalanceAfter = await SOLD_TOKEN.balanceOf( - TokenSaleConductor.address - ); + const actualContributorBalanceAfter = await SOLD_TOKEN.balanceOf(TokenSaleContributor.address); + const actualConductorBalanceAfter = await SOLD_TOKEN.balanceOf(TokenSaleConductor.address); - assert.equal( - actualContributorBalanceAfter, - expectedContributorBalanceAfter - ); + assert.equal(actualContributorBalanceAfter, expectedContributorBalanceAfter); assert.equal(actualConductorBalanceAfter, expectedConductorBalanceAfter); const log = ( @@ -1711,18 +1345,11 @@ contract("ICCO", function(accounts) { const expectedRecipientTokenOneBalanceChange = "10000"; const expectedRecipientTokenTwoBalanceChange = "7500"; - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); // grab contributed token balance before for sale recipient - const receipientTokenOneBalanceBefore = await CONTRIBUTED_TOKEN_ONE.balanceOf( - SELLER - ); - const receipientTokenTwoBalanceBefore = await CONTRIBUTED_TOKEN_TWO.balanceOf( - SELLER - ); + const receipientTokenOneBalanceBefore = await CONTRIBUTED_TOKEN_ONE.balanceOf(SELLER); + const receipientTokenTwoBalanceBefore = await CONTRIBUTED_TOKEN_TWO.balanceOf(SELLER); // verify sealSealed getters before calling saleSealed const saleBefore = await initialized.methods.sales(SALE_ID).call(); @@ -1758,34 +1385,22 @@ contract("ICCO", function(accounts) { assert.ok(saleAfter.isSealed); // verify getSaleAllocation after sealing the sale - const actualAllocationTokenOne = await initialized.methods - .getSaleAllocation(SALE_ID, TOKEN_ONE_INDEX) - .call(); - const actualAllocationTokenTwo = await initialized.methods - .getSaleAllocation(SALE_ID, TOKEN_TWO_INDEX) - .call(); + const actualAllocationTokenOne = await initialized.methods.getSaleAllocation(SALE_ID, TOKEN_ONE_INDEX).call(); + const actualAllocationTokenTwo = await initialized.methods.getSaleAllocation(SALE_ID, TOKEN_TWO_INDEX).call(); assert.equal(actualAllocationTokenOne, expectedAllocationTokenOne); assert.equal(actualAllocationTokenTwo, expectedAllocationTokenTwo); // verify getSaleAllocation after sealing the sale - const actualExcessTokenOne = await initialized.methods - .getSaleExcessContribution(SALE_ID, TOKEN_ONE_INDEX) - .call(); - const actualExcessTokenTwo = await initialized.methods - .getSaleExcessContribution(SALE_ID, TOKEN_TWO_INDEX) - .call(); + const actualExcessTokenOne = await initialized.methods.getSaleExcessContribution(SALE_ID, TOKEN_ONE_INDEX).call(); + const actualExcessTokenTwo = await initialized.methods.getSaleExcessContribution(SALE_ID, TOKEN_TWO_INDEX).call(); assert.equal(actualExcessTokenOne, expectedExcessTokenOne); assert.equal(actualExcessTokenTwo, expectedExcessTokenTwo); // confirm that the sale recipient recieved the correct amount of contributions - const receipientTokenOneBalanceAfter = await CONTRIBUTED_TOKEN_ONE.balanceOf( - SELLER - ); - const receipientTokenTwoBalanceAfter = await CONTRIBUTED_TOKEN_TWO.balanceOf( - SELLER - ); + const receipientTokenOneBalanceAfter = await CONTRIBUTED_TOKEN_ONE.balanceOf(SELLER); + const receipientTokenTwoBalanceAfter = await CONTRIBUTED_TOKEN_TWO.balanceOf(SELLER); assert.equal( receipientTokenOneBalanceAfter - receipientTokenOneBalanceBefore, @@ -1808,22 +1423,14 @@ contract("ICCO", function(accounts) { const expectedBuyerOneBalanceAfter = "600"; const expectedBuyerTwoBalanceAfter = "400"; - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); // check balances before claiming allocations - const actualContributorBalanceBefore = await SOLD_TOKEN.balanceOf( - TokenSaleContributor.address - ); + const actualContributorBalanceBefore = await SOLD_TOKEN.balanceOf(TokenSaleContributor.address); const actualBuyerOneBalanceBefore = await SOLD_TOKEN.balanceOf(BUYER_ONE); const actualBuyerTwoBalanceBefore = await SOLD_TOKEN.balanceOf(BUYER_TWO); - assert.equal( - actualContributorBalanceBefore, - expectedContributorBalanceBefore - ); + assert.equal(actualContributorBalanceBefore, expectedContributorBalanceBefore); assert.equal(actualBuyerOneBalanceBefore, expectedBuyerOneBalanceBefore); assert.equal(actualBuyerTwoBalanceBefore, expectedBuyerTwoBalanceBefore); @@ -1843,17 +1450,16 @@ contract("ICCO", function(accounts) { assert.ok(!isAllocationClaimedTokenTwoBefore); // claim allocations for both tokens - const claimTx1 = await initialized.methods - .claimAllocation(SALE_ID, TOKEN_TWO_INDEX) - .send({ - from: BUYER_TWO, - gasLimit: GAS_LIMIT, - }); + const claimTx1 = await initialized.methods.claimAllocation(SALE_ID, TOKEN_TWO_INDEX).send({ + from: BUYER_TWO, + gasLimit: GAS_LIMIT, + }); // confirm that the EventClaimAllocation event was emitted let eventClaim = claimTx1["events"]["EventClaimAllocation"]["returnValues"]; assert.equal(eventClaim["saleId"], SALE_ID); assert.equal(eventClaim["tokenIndex"], TOKEN_TWO_INDEX); + assert.equal(eventClaim["amount"], expectedBuyerTwoBalanceAfter); ONE_CLAIM_SNAPSHOT = await snapshot(); @@ -1868,16 +1474,11 @@ contract("ICCO", function(accounts) { }); // check balances after claiming allocations - const actualContributorBalanceAfter = await SOLD_TOKEN.balanceOf( - TokenSaleContributor.address - ); + const actualContributorBalanceAfter = await SOLD_TOKEN.balanceOf(TokenSaleContributor.address); const actualBuyerOneBalanceAfter = await SOLD_TOKEN.balanceOf(BUYER_ONE); const actualBuyerTwoBalanceAfter = await SOLD_TOKEN.balanceOf(BUYER_TWO); - assert.equal( - actualContributorBalanceAfter, - expectedContributorBalanceAfter - ); + assert.equal(actualContributorBalanceAfter, expectedContributorBalanceAfter); assert.equal(actualBuyerOneBalanceAfter, expectedBuyerOneBalanceAfter); assert.equal(actualBuyerTwoBalanceAfter, expectedBuyerTwoBalanceAfter); @@ -1901,10 +1502,7 @@ contract("ICCO", function(accounts) { // revert first allocation claim await revert(ONE_CLAIM_SNAPSHOT); - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); let failed = false; try { @@ -1924,19 +1522,14 @@ contract("ICCO", function(accounts) { }); it("excess contribution should not be claimable when maxRaise is not exceeded", async function() { - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); let failed = false; try { - await initialized.methods - .claimExcessContribution(SALE_ID, TOKEN_ONE_INDEX) - .send({ - from: BUYER_ONE, - gasLimit: GAS_LIMIT, - }); + await initialized.methods.claimExcessContribution(SALE_ID, TOKEN_ONE_INDEX).send({ + from: BUYER_ONE, + gasLimit: GAS_LIMIT, + }); } catch (e) { assert.equal( e.message, @@ -1974,10 +1567,7 @@ contract("ICCO", function(accounts) { const payloadIdType1 = "01"; const isFixedPriceSale = false; - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); await SOLD_TOKEN.approve(TokenSaleConductor.address, saleTokenAmount); @@ -2000,16 +1590,8 @@ contract("ICCO", function(accounts) { // create accepted tokens array const acceptedTokens = [ - [ - TEST_CHAIN_ID, - "0x000000000000000000000000" + CONTRIBUTED_TOKEN_ONE.address.substr(2), - tokenOneConversionRate, - ], - [ - TEST_CHAIN_ID, - "0x000000000000000000000000" + CONTRIBUTED_TOKEN_TWO.address.substr(2), - tokenTwoConversionRate, - ], + [TEST_CHAIN_ID, "0x000000000000000000000000" + CONTRIBUTED_TOKEN_ONE.address.substr(2), tokenOneConversionRate], + [TEST_CHAIN_ID, "0x000000000000000000000000" + CONTRIBUTED_TOKEN_TWO.address.substr(2), tokenTwoConversionRate], ]; // create a second sale @@ -2047,17 +1629,12 @@ contract("ICCO", function(accounts) { // token chain assert.equal( log.payload.substr(index, 4), - web3.eth.abi - .encodeParameter("uint16", TEST_CHAIN_ID) - .substring(2 + 64 - 4) + web3.eth.abi.encodeParameter("uint16", TEST_CHAIN_ID).substring(2 + 64 - 4) ); index += 4; // token decimals - assert.equal( - parseInt(log.payload.substr(index, 2), 16), - SOLD_TOKEN_DECIMALS - ); + assert.equal(parseInt(log.payload.substr(index, 2), 16), SOLD_TOKEN_DECIMALS); index += 2; // timestamp start @@ -2069,74 +1646,51 @@ contract("ICCO", function(accounts) { index += 64; // accepted tokens length - assert.equal( - parseInt(log.payload.substr(index, 2), 16), - acceptedTokenLength - ); + assert.equal(parseInt(log.payload.substr(index, 2), 16), acceptedTokenLength); index += 2; // token address assert.equal( log.payload.substr(index, 64), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address).substring(2) ); index += 64; // token chain assert.equal( log.payload.substr(index, 4), - web3.eth.abi - .encodeParameter("uint16", TEST_CHAIN_ID) - .substring(2 + 64 - 4) + web3.eth.abi.encodeParameter("uint16", TEST_CHAIN_ID).substring(2 + 64 - 4) ); index += 4; // conversion rate - assert.equal( - parseInt(log.payload.substr(index, 32), 16), - parseInt(tokenOneConversionRate) - ); + assert.equal(parseInt(log.payload.substr(index, 32), 16), parseInt(tokenOneConversionRate)); index += 32; // token address assert.equal( log.payload.substr(index, 64), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address).substring(2) ); index += 64; // token chain assert.equal( log.payload.substr(index, 4), - web3.eth.abi - .encodeParameter("uint16", TEST_CHAIN_ID) - .substring(2 + 64 - 4) + web3.eth.abi.encodeParameter("uint16", TEST_CHAIN_ID).substring(2 + 64 - 4) ); index += 4; // conversion rate - assert.equal( - parseInt(log.payload.substr(index, 32), 16), - parseInt(tokenTwoConversionRate) - ); + assert.equal(parseInt(log.payload.substr(index, 32), 16), parseInt(tokenTwoConversionRate)); index += 32; // recipient of proceeds - assert.equal( - log.payload.substr(index, 64), - web3.eth.abi.encodeParameter("address", saleRecipient).substring(2) - ); + assert.equal(log.payload.substr(index, 64), web3.eth.abi.encodeParameter("address", saleRecipient).substring(2)); index += 64; // KYC authority public key - assert.equal( - log.payload.substr(index, 40), - web3.eth.abi.encodeParameter("address", KYC_AUTHORITY).substring(26) - ); + assert.equal(log.payload.substr(index, 40), web3.eth.abi.encodeParameter("address", KYC_AUTHORITY).substring(26)); index += 40; // unlock timestamp @@ -2163,10 +1717,7 @@ contract("ICCO", function(accounts) { const tokenTwoConversionRate = "2000000000000000000"; const saleRecipient = accounts[0]; - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); const vm = await signAndEncodeVM( 1, @@ -2200,30 +1751,17 @@ contract("ICCO", function(accounts) { assert.equal(sale.unlockTimestamp, SALE_2_END); assert.equal( sale.acceptedTokensAddresses[TOKEN_ONE_INDEX].substring(2), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address).substring(2) ); assert.equal(sale.acceptedTokensChains[TOKEN_ONE_INDEX], TEST_CHAIN_ID); - assert.equal( - sale.acceptedTokensConversionRates[TOKEN_ONE_INDEX], - tokenOneConversionRate - ); + assert.equal(sale.acceptedTokensConversionRates[TOKEN_ONE_INDEX], tokenOneConversionRate); assert.equal( sale.acceptedTokensAddresses[TOKEN_TWO_INDEX].substring(2), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address).substring(2) ); assert.equal(sale.acceptedTokensChains[TOKEN_TWO_INDEX], TEST_CHAIN_ID); - assert.equal( - sale.acceptedTokensConversionRates[TOKEN_TWO_INDEX], - tokenTwoConversionRate - ); - assert.equal( - sale.recipient.substring(2), - web3.eth.abi.encodeParameter("address", saleRecipient).substring(2) - ); + assert.equal(sale.acceptedTokensConversionRates[TOKEN_TWO_INDEX], tokenTwoConversionRate); + assert.equal(sale.recipient.substring(2), web3.eth.abi.encodeParameter("address", saleRecipient).substring(2)); assert.equal(sale.authority.substring(2), KYC_AUTHORITY.substring(2)); assert.equal(sale.allocations[TOKEN_ONE_INDEX], 0); assert.equal(sale.allocations[TOKEN_TWO_INDEX], 0); @@ -2233,43 +1771,31 @@ contract("ICCO", function(accounts) { assert.ok(!sale.isAborted); // verify getsaleAcceptedTokenInfo getter - const tokenOneInfo = await initialized.methods - .getSaleAcceptedTokenInfo(SALE_2_ID, TOKEN_ONE_INDEX) - .call(); - const tokenTwoInfo = await initialized.methods - .getSaleAcceptedTokenInfo(SALE_2_ID, TOKEN_TWO_INDEX) - .call(); + const tokenOneInfo = await initialized.methods.getSaleAcceptedTokenInfo(SALE_2_ID, TOKEN_ONE_INDEX).call(); + const tokenTwoInfo = await initialized.methods.getSaleAcceptedTokenInfo(SALE_2_ID, TOKEN_TWO_INDEX).call(); assert.equal( tokenOneInfo.tokenAddress.substring(2), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address).substring(2) ); assert.equal(tokenOneInfo.tokenChainId, TEST_CHAIN_ID); assert.equal(tokenOneInfo.conversionRate, tokenOneConversionRate); assert.equal( tokenTwoInfo.tokenAddress.substring(2), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address).substring(2) ); assert.equal(tokenTwoInfo.tokenChainId, TEST_CHAIN_ID); assert.equal(tokenTwoInfo.conversionRate, tokenTwoConversionRate); // verify getSaleTimeFrame getter - const saleTimeframe = await initialized.methods - .getSaleTimeframe(SALE_2_ID) - .call(); + const saleTimeframe = await initialized.methods.getSaleTimeframe(SALE_2_ID).call(); assert.equal(saleTimeframe.start, SALE_2_START); assert.equal(saleTimeframe.end, SALE_2_END); assert.equal(saleTimeframe.unlockTimestamp, SALE_2_END); // verify getSaleStatus getter - const saleStatus = await initialized.methods - .getSaleStatus(SALE_2_ID) - .call(); + const saleStatus = await initialized.methods.getSaleStatus(SALE_2_ID).call(); assert.ok(!saleStatus.isSealed); assert.ok(!saleStatus.isAborted); @@ -2282,34 +1808,22 @@ contract("ICCO", function(accounts) { const tokenOneContributionAmount = ["500", "500"]; const tokenTwoContributionAmount = ["100", "100"]; - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); // approve contribution amounts await CONTRIBUTED_TOKEN_ONE.approve( TokenSaleContributor.address, - parseInt(tokenOneContributionAmount[0]) + - parseInt(tokenOneContributionAmount[1]), - { - from: BUYER_ONE, - } - ); - await CONTRIBUTED_TOKEN_TWO.approve( - TokenSaleContributor.address, - tokenTwoContributionAmount[0], - { - from: BUYER_TWO, - } - ); - await CONTRIBUTED_TOKEN_TWO.approve( - TokenSaleContributor.address, - tokenTwoContributionAmount[1], + parseInt(tokenOneContributionAmount[0]) + parseInt(tokenOneContributionAmount[1]), { from: BUYER_ONE, } ); + await CONTRIBUTED_TOKEN_TWO.approve(TokenSaleContributor.address, tokenTwoContributionAmount[0], { + from: BUYER_TWO, + }); + await CONTRIBUTED_TOKEN_TWO.approve(TokenSaleContributor.address, tokenTwoContributionAmount[1], { + from: BUYER_ONE, + }); // perform "kyc" and contribute tokens to the sale for BUYER_ONE const kycSig1 = await signContribution( @@ -2321,12 +1835,7 @@ contract("ICCO", function(accounts) { kycSignerPK ); await initialized.methods - .contribute( - SALE_2_ID, - TOKEN_ONE_INDEX, - parseInt(tokenOneContributionAmount[0]), - kycSig1 - ) + .contribute(SALE_2_ID, TOKEN_ONE_INDEX, parseInt(tokenOneContributionAmount[0]), kycSig1) .send({ from: BUYER_ONE, gasLimit: GAS_LIMIT, @@ -2341,12 +1850,7 @@ contract("ICCO", function(accounts) { kycSignerPK ); await initialized.methods - .contribute( - SALE_2_ID, - TOKEN_ONE_INDEX, - parseInt(tokenOneContributionAmount[1]), - kycSig2 - ) + .contribute(SALE_2_ID, TOKEN_ONE_INDEX, parseInt(tokenOneContributionAmount[1]), kycSig2) .send({ from: BUYER_ONE, gasLimit: GAS_LIMIT, @@ -2361,12 +1865,7 @@ contract("ICCO", function(accounts) { kycSignerPK ); await initialized.methods - .contribute( - SALE_2_ID, - TOKEN_TWO_INDEX, - parseInt(tokenTwoContributionAmount[1]), - kycSig3 - ) + .contribute(SALE_2_ID, TOKEN_TWO_INDEX, parseInt(tokenTwoContributionAmount[1]), kycSig3) .send({ from: BUYER_ONE, gasLimit: GAS_LIMIT, @@ -2382,12 +1881,7 @@ contract("ICCO", function(accounts) { kycSignerPK ); await initialized.methods - .contribute( - SALE_2_ID, - TOKEN_TWO_INDEX, - parseInt(tokenTwoContributionAmount[0]), - kycSig4 - ) + .contribute(SALE_2_ID, TOKEN_TWO_INDEX, parseInt(tokenTwoContributionAmount[0]), kycSig4) .send({ from: BUYER_TWO, gasLimit: GAS_LIMIT, @@ -2403,13 +1897,11 @@ contract("ICCO", function(accounts) { assert.equal( totalContributionsTokenOne, - parseInt(tokenOneContributionAmount[0]) + - parseInt(tokenOneContributionAmount[1]) + parseInt(tokenOneContributionAmount[0]) + parseInt(tokenOneContributionAmount[1]) ); assert.equal( totalContributionsTokenTwo, - parseInt(tokenTwoContributionAmount[0]) + - parseInt(tokenTwoContributionAmount[1]) + parseInt(tokenTwoContributionAmount[0]) + parseInt(tokenTwoContributionAmount[1]) ); // verify getSaleContribution @@ -2425,13 +1917,9 @@ contract("ICCO", function(accounts) { assert.equal( buyerOneContributionTokenOne, - parseInt(tokenOneContributionAmount[0]) + - parseInt(tokenOneContributionAmount[1]) - ); - assert.equal( - buyerOneContributionTokenTwo, - parseInt(tokenTwoContributionAmount[1]) + parseInt(tokenOneContributionAmount[0]) + parseInt(tokenOneContributionAmount[1]) ); + assert.equal(buyerOneContributionTokenTwo, parseInt(tokenTwoContributionAmount[1])); assert.equal(buyerTwoContribution, parseInt(tokenTwoContributionAmount[0])); }); @@ -2446,10 +1934,7 @@ contract("ICCO", function(accounts) { const acceptedTokenLength = 2; const payloadIdType2 = "02"; - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); // attest contributions await initialized.methods.attestContributions(SALE_2_ID).send({ @@ -2476,45 +1961,27 @@ contract("ICCO", function(accounts) { index += 64; // chain id - assert.equal( - log.payload.substr(index, 4), - web3.eth.abi.encodeParameter("uint16", 2).substring(2 + 64 - 4) - ); + assert.equal(log.payload.substr(index, 4), web3.eth.abi.encodeParameter("uint16", 2).substring(2 + 64 - 4)); index += 4; // tokens length - assert.equal( - parseInt(log.payload.substr(index, 2), 16), - acceptedTokenLength - ); + assert.equal(parseInt(log.payload.substr(index, 2), 16), acceptedTokenLength); index += 2; // token index - assert.equal( - log.payload.substr(index, 2), - web3.eth.abi.encodeParameter("uint8", 0).substring(2 + 64 - 2) - ); + assert.equal(log.payload.substr(index, 2), web3.eth.abi.encodeParameter("uint8", 0).substring(2 + 64 - 2)); index += 2; // amount - assert.equal( - parseInt(log.payload.substr(index, 64), 16), - tokenOneContributionAmount - ); + assert.equal(parseInt(log.payload.substr(index, 64), 16), tokenOneContributionAmount); index += 64; // token index - assert.equal( - log.payload.substr(index, 2), - web3.eth.abi.encodeParameter("uint8", 1).substring(2 + 64 - 2) - ); + assert.equal(log.payload.substr(index, 2), web3.eth.abi.encodeParameter("uint8", 1).substring(2 + 64 - 2)); index += 2; // amount - assert.equal( - parseInt(log.payload.substr(index, 64), 16), - tokenTwoContributionAmount - ); + assert.equal(parseInt(log.payload.substr(index, 64), 16), tokenTwoContributionAmount); index += 64; assert.equal(log.payload.length, index); @@ -2527,10 +1994,7 @@ contract("ICCO", function(accounts) { const tokenOneContributionAmount = "1000"; const tokenTwoContributionAmount = "200"; - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); // verify saleContributionIsCollected getter before calling contribute const isContributionOneCollectedBefore = await initialized.methods @@ -2573,9 +2037,7 @@ contract("ICCO", function(accounts) { assert.ok(isContributionTwoCollectedAfter); // verify saleContributions getter - const contributions = await initialized.methods - .saleContributions(SALE_2_ID) - .call(); + const contributions = await initialized.methods.saleContributions(SALE_2_ID).call(); assert.equal(contributions[0], tokenOneContributionAmount); assert.equal(contributions[1], tokenTwoContributionAmount); @@ -2591,20 +2053,11 @@ contract("ICCO", function(accounts) { const expectedRefundRecipientBalanceChange = "1000"; const payloadIdType4 = "04"; - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); - const actualContributorBalanceBefore = await SOLD_TOKEN.balanceOf( - TokenSaleContributor.address - ); - const actualConductorBalanceBefore = await SOLD_TOKEN.balanceOf( - TokenSaleConductor.address - ); - const refundRecipientBalanceBefore = await SOLD_TOKEN.balanceOf( - SALE_2_REFUND_RECIPIENT - ); + const actualContributorBalanceBefore = await SOLD_TOKEN.balanceOf(TokenSaleContributor.address); + const actualConductorBalanceBefore = await SOLD_TOKEN.balanceOf(TokenSaleConductor.address); + const refundRecipientBalanceBefore = await SOLD_TOKEN.balanceOf(SALE_2_REFUND_RECIPIENT); // confirm that the sale is not aborted yet const saleBefore = await initialized.methods.sales(SALE_2_ID).call(); @@ -2623,26 +2076,18 @@ contract("ICCO", function(accounts) { }); // confirm that the EventAbortSale event was emitted - const eventSealAbort = - sealAbortTx["events"]["EventAbortSale"]["returnValues"]; + const eventSealAbort = sealAbortTx["events"]["EventAbortSale"]["returnValues"]; assert.equal(eventSealAbort["saleId"], SALE_2_ID); - const actualContributorBalanceAfter = await SOLD_TOKEN.balanceOf( - TokenSaleContributor.address - ); - const actualConductorBalanceAfter = await SOLD_TOKEN.balanceOf( - TokenSaleConductor.address - ); - const refundRecipientBalanceAfter = await SOLD_TOKEN.balanceOf( - SALE_2_REFUND_RECIPIENT - ); + const actualContributorBalanceAfter = await SOLD_TOKEN.balanceOf(TokenSaleContributor.address); + const actualConductorBalanceAfter = await SOLD_TOKEN.balanceOf(TokenSaleConductor.address); + const refundRecipientBalanceAfter = await SOLD_TOKEN.balanceOf(SALE_2_REFUND_RECIPIENT); // check balances after sealing the sale assert.equal(actualContributorBalanceAfter, expectedContributorBalance); assert.equal(actualConductorBalanceAfter, expectedConductorBalanceAfter); assert.equal( - parseInt(refundRecipientBalanceAfter) - - parseInt(refundRecipientBalanceBefore), + parseInt(refundRecipientBalanceAfter) - parseInt(refundRecipientBalanceBefore), expectedRefundRecipientBalanceChange ); @@ -2666,33 +2111,21 @@ contract("ICCO", function(accounts) { index += 2; // sale id - assert.equal( - parseInt(SALE_SEALED_PAYLOAD_2.substr(index, 64), 16), - SALE_2_ID - ); + assert.equal(parseInt(SALE_SEALED_PAYLOAD_2.substr(index, 64), 16), SALE_2_ID); index += 64; // send refunded tokens back to SELLER account await SOLD_TOKEN.approve(SELLER, expectedRefundRecipientBalanceChange, { from: SALE_2_REFUND_RECIPIENT, }); - await SOLD_TOKEN.transferFrom( - SALE_2_REFUND_RECIPIENT, - SELLER, - expectedRefundRecipientBalanceChange - ); + await SOLD_TOKEN.transferFrom(SALE_2_REFUND_RECIPIENT, SELLER, expectedRefundRecipientBalanceChange); }); it("contributor should abort second sale correctly", async function() { - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); // verify getSaleStatus before aborting in contributor - const statusBefore = await initialized.methods - .getSaleStatus(SALE_2_ID) - .call(); + const statusBefore = await initialized.methods.getSaleStatus(SALE_2_ID).call(); assert.ok(!statusBefore.isAborted); assert.ok(!statusBefore.isSealed); @@ -2716,9 +2149,7 @@ contract("ICCO", function(accounts) { }); // confirm that saleAborted was set to true - const statusAfter = await initialized.methods - .getSaleStatus(SALE_2_ID) - .call(); + const statusAfter = await initialized.methods.getSaleStatus(SALE_2_ID).call(); assert.ok(statusAfter.isAborted); assert.ok(!statusAfter.isSealed); @@ -2739,10 +2170,7 @@ contract("ICCO", function(accounts) { const expectedBuyerOneTokenTwoBalanceAfter = "2500"; const expectedBuyerTwoBalanceAfter = "15000"; - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); // confirm refundIsClaimed is set to false const buyerOneHasClaimedRefundBefore = await initialized.methods @@ -2756,55 +2184,35 @@ contract("ICCO", function(accounts) { assert.ok(!buyerTwoHasClaimedRefundBefore); // check balances of contributed tokens on the contributor - const actualContributorTokenOneBalanceBefore = await CONTRIBUTED_TOKEN_ONE.balanceOf( - TokenSaleContributor.address - ); - const actualContributorTokenTwoBalanceBefore = await CONTRIBUTED_TOKEN_TWO.balanceOf( - TokenSaleContributor.address - ); + const actualContributorTokenOneBalanceBefore = await CONTRIBUTED_TOKEN_ONE.balanceOf(TokenSaleContributor.address); + const actualContributorTokenTwoBalanceBefore = await CONTRIBUTED_TOKEN_TWO.balanceOf(TokenSaleContributor.address); - assert.equal( - actualContributorTokenOneBalanceBefore, - expectedContributorTokenOneBalanceBefore - ); - assert.equal( - actualContributorTokenTwoBalanceBefore, - expectedContributorTokenTwoBalanceBefore - ); + assert.equal(actualContributorTokenOneBalanceBefore, expectedContributorTokenOneBalanceBefore); + assert.equal(actualContributorTokenTwoBalanceBefore, expectedContributorTokenTwoBalanceBefore); // check buyer balances - const actualBuyerOneTokenOneBalanceBefore = await CONTRIBUTED_TOKEN_ONE.balanceOf( - BUYER_ONE - ); - const actualBuyerOneTokenTwoBalanceBefore = await CONTRIBUTED_TOKEN_TWO.balanceOf( - BUYER_ONE - ); - const actualBuyerTwoBalanceBefore = await CONTRIBUTED_TOKEN_TWO.balanceOf( - BUYER_TWO - ); + const actualBuyerOneTokenOneBalanceBefore = await CONTRIBUTED_TOKEN_ONE.balanceOf(BUYER_ONE); + const actualBuyerOneTokenTwoBalanceBefore = await CONTRIBUTED_TOKEN_TWO.balanceOf(BUYER_ONE); + const actualBuyerTwoBalanceBefore = await CONTRIBUTED_TOKEN_TWO.balanceOf(BUYER_TWO); - assert.equal( - actualBuyerOneTokenOneBalanceBefore, - expectedBuyerOneTokenOneBalanceBefore - ); - assert.equal( - actualBuyerOneTokenTwoBalanceBefore, - expectedBuyerOneTokenTwoBalanceBefore - ); + assert.equal(actualBuyerOneTokenOneBalanceBefore, expectedBuyerOneTokenOneBalanceBefore); + assert.equal(actualBuyerOneTokenTwoBalanceBefore, expectedBuyerOneTokenTwoBalanceBefore); assert.equal(actualBuyerTwoBalanceBefore, expectedBuyerTwoBalanceBefore); // BUYER_ONE/BUYER_TWO claims refunds - const refundTx1 = await initialized.methods - .claimRefund(SALE_2_ID, TOKEN_ONE_INDEX) - .send({ - from: BUYER_ONE, - gasLimit: GAS_LIMIT, - }); + const refundTx1 = await initialized.methods.claimRefund(SALE_2_ID, TOKEN_ONE_INDEX).send({ + from: BUYER_ONE, + gasLimit: GAS_LIMIT, + }); // confirm that the EventClaimRefund event was emitted let eventClaim = refundTx1["events"]["EventClaimRefund"]["returnValues"]; assert.equal(eventClaim["saleId"], SALE_2_ID); assert.equal(eventClaim["tokenIndex"], TOKEN_ONE_INDEX); + assert.equal( + eventClaim["amount"], + parseInt(expectedBuyerOneTokenOneBalanceAfter) - parseInt(actualBuyerOneTokenOneBalanceBefore) + ); // snapshot to test trying to claim refund 2x ONE_REFUND_SNAPSHOT = await snapshot(); @@ -2819,41 +2227,19 @@ contract("ICCO", function(accounts) { }); // check balances of contributed tokens on contributor - const actualContributorTokenOneBalanceAfter = await CONTRIBUTED_TOKEN_ONE.balanceOf( - TokenSaleContributor.address - ); - const actualContributorTokenTwoBalanceAfter = await CONTRIBUTED_TOKEN_TWO.balanceOf( - TokenSaleContributor.address - ); + const actualContributorTokenOneBalanceAfter = await CONTRIBUTED_TOKEN_ONE.balanceOf(TokenSaleContributor.address); + const actualContributorTokenTwoBalanceAfter = await CONTRIBUTED_TOKEN_TWO.balanceOf(TokenSaleContributor.address); - assert.equal( - actualContributorTokenOneBalanceAfter, - expectedContributorTokenOneBalanceAfter - ); - assert.equal( - actualContributorTokenTwoBalanceAfter, - expectedContributorTokenTwoBalanceAfter - ); + assert.equal(actualContributorTokenOneBalanceAfter, expectedContributorTokenOneBalanceAfter); + assert.equal(actualContributorTokenTwoBalanceAfter, expectedContributorTokenTwoBalanceAfter); // check buyer balances after claiming refund - const actualBuyerOneTokenOneBalanceAfter = await CONTRIBUTED_TOKEN_ONE.balanceOf( - BUYER_ONE - ); - const actualBuyerOneTokenTwoBalanceAfter = await CONTRIBUTED_TOKEN_TWO.balanceOf( - BUYER_ONE - ); - const actualBuyerTwoBalanceAfter = await CONTRIBUTED_TOKEN_TWO.balanceOf( - BUYER_TWO - ); + const actualBuyerOneTokenOneBalanceAfter = await CONTRIBUTED_TOKEN_ONE.balanceOf(BUYER_ONE); + const actualBuyerOneTokenTwoBalanceAfter = await CONTRIBUTED_TOKEN_TWO.balanceOf(BUYER_ONE); + const actualBuyerTwoBalanceAfter = await CONTRIBUTED_TOKEN_TWO.balanceOf(BUYER_TWO); - assert.equal( - actualBuyerOneTokenOneBalanceAfter, - expectedBuyerOneTokenOneBalanceAfter - ); - assert.equal( - actualBuyerOneTokenTwoBalanceAfter, - expectedBuyerOneTokenTwoBalanceAfter - ); + assert.equal(actualBuyerOneTokenOneBalanceAfter, expectedBuyerOneTokenOneBalanceAfter); + assert.equal(actualBuyerOneTokenTwoBalanceAfter, expectedBuyerOneTokenTwoBalanceAfter); assert.equal(actualBuyerTwoBalanceAfter, expectedBuyerTwoBalanceAfter); // confirm refundIsClaimed is set to true @@ -2869,10 +2255,7 @@ contract("ICCO", function(accounts) { }); it("refund should only be claimable once in contributor", async function() { - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); // revert the refund so we can try to claim it again await revert(ONE_REFUND_SNAPSHOT); @@ -2901,9 +2284,7 @@ contract("ICCO", function(accounts) { let SALE_3_ID; it("create a third sale correctly and attest over wormhole", async function() { - console.log( - "\n -------------------------- Sale Test #3 (Aborted Early) --------------------------" - ); + console.log("\n -------------------------- Sale Test #3 (Aborted Early) --------------------------"); // test variables const current_block = await web3.eth.getBlock("latest"); @@ -2920,10 +2301,7 @@ contract("ICCO", function(accounts) { const payloadIdType1 = "01"; const isFixedPriceSale = false; - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); await SOLD_TOKEN.approve(TokenSaleConductor.address, saleTokenAmount); @@ -2946,16 +2324,8 @@ contract("ICCO", function(accounts) { // create accepted tokens array const acceptedTokens = [ - [ - TEST_CHAIN_ID, - "0x000000000000000000000000" + CONTRIBUTED_TOKEN_ONE.address.substr(2), - tokenOneConversionRate, - ], - [ - TEST_CHAIN_ID, - "0x000000000000000000000000" + CONTRIBUTED_TOKEN_TWO.address.substr(2), - tokenTwoConversionRate, - ], + [TEST_CHAIN_ID, "0x000000000000000000000000" + CONTRIBUTED_TOKEN_ONE.address.substr(2), tokenOneConversionRate], + [TEST_CHAIN_ID, "0x000000000000000000000000" + CONTRIBUTED_TOKEN_TWO.address.substr(2), tokenTwoConversionRate], ]; // create a third sale @@ -2993,17 +2363,12 @@ contract("ICCO", function(accounts) { // token chain assert.equal( log.payload.substr(index, 4), - web3.eth.abi - .encodeParameter("uint16", TEST_CHAIN_ID) - .substring(2 + 64 - 4) + web3.eth.abi.encodeParameter("uint16", TEST_CHAIN_ID).substring(2 + 64 - 4) ); index += 4; // token decimals - assert.equal( - parseInt(log.payload.substr(index, 2), 16), - SOLD_TOKEN_DECIMALS - ); + assert.equal(parseInt(log.payload.substr(index, 2), 16), SOLD_TOKEN_DECIMALS); index += 2; // timestamp start @@ -3015,74 +2380,51 @@ contract("ICCO", function(accounts) { index += 64; // accepted tokens length - assert.equal( - parseInt(log.payload.substr(index, 2), 16), - acceptedTokenLength - ); + assert.equal(parseInt(log.payload.substr(index, 2), 16), acceptedTokenLength); index += 2; // token address assert.equal( log.payload.substr(index, 64), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address).substring(2) ); index += 64; // token chain assert.equal( log.payload.substr(index, 4), - web3.eth.abi - .encodeParameter("uint16", TEST_CHAIN_ID) - .substring(2 + 64 - 4) + web3.eth.abi.encodeParameter("uint16", TEST_CHAIN_ID).substring(2 + 64 - 4) ); index += 4; // conversion rate - assert.equal( - parseInt(log.payload.substr(index, 32), 16), - parseInt(tokenOneConversionRate) - ); + assert.equal(parseInt(log.payload.substr(index, 32), 16), parseInt(tokenOneConversionRate)); index += 32; // token address assert.equal( log.payload.substr(index, 64), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address).substring(2) ); index += 64; // token chain assert.equal( log.payload.substr(index, 4), - web3.eth.abi - .encodeParameter("uint16", TEST_CHAIN_ID) - .substring(2 + 64 - 4) + web3.eth.abi.encodeParameter("uint16", TEST_CHAIN_ID).substring(2 + 64 - 4) ); index += 4; // conversion rate - assert.equal( - parseInt(log.payload.substr(index, 32), 16), - parseInt(tokenTwoConversionRate) - ); + assert.equal(parseInt(log.payload.substr(index, 32), 16), parseInt(tokenTwoConversionRate)); index += 32; // recipient of proceeds - assert.equal( - log.payload.substr(index, 64), - web3.eth.abi.encodeParameter("address", saleRecipient).substring(2) - ); + assert.equal(log.payload.substr(index, 64), web3.eth.abi.encodeParameter("address", saleRecipient).substring(2)); index += 64; // KYC authority public key - assert.equal( - log.payload.substr(index, 40), - web3.eth.abi.encodeParameter("address", KYC_AUTHORITY).substring(26) - ); + assert.equal(log.payload.substr(index, 40), web3.eth.abi.encodeParameter("address", KYC_AUTHORITY).substring(26)); index += 40; // unlock timestamp @@ -3109,10 +2451,7 @@ contract("ICCO", function(accounts) { const tokenTwoConversionRate = "2000000000000000000"; const saleRecipient = accounts[0]; - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); const vm = await signAndEncodeVM( 1, @@ -3146,30 +2485,17 @@ contract("ICCO", function(accounts) { assert.equal(sale.unlockTimestamp, SALE_3_END); assert.equal( sale.acceptedTokensAddresses[TOKEN_ONE_INDEX].substring(2), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address).substring(2) ); assert.equal(sale.acceptedTokensChains[TOKEN_ONE_INDEX], TEST_CHAIN_ID); - assert.equal( - sale.acceptedTokensConversionRates[TOKEN_ONE_INDEX], - tokenOneConversionRate - ); + assert.equal(sale.acceptedTokensConversionRates[TOKEN_ONE_INDEX], tokenOneConversionRate); assert.equal( sale.acceptedTokensAddresses[TOKEN_TWO_INDEX].substring(2), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address).substring(2) ); assert.equal(sale.acceptedTokensChains[TOKEN_TWO_INDEX], TEST_CHAIN_ID); - assert.equal( - sale.acceptedTokensConversionRates[TOKEN_TWO_INDEX], - tokenTwoConversionRate - ); - assert.equal( - sale.recipient.substring(2), - web3.eth.abi.encodeParameter("address", saleRecipient).substring(2) - ); + assert.equal(sale.acceptedTokensConversionRates[TOKEN_TWO_INDEX], tokenTwoConversionRate); + assert.equal(sale.recipient.substring(2), web3.eth.abi.encodeParameter("address", saleRecipient).substring(2)); assert.equal(sale.authority.substring(2), KYC_AUTHORITY.substring(2)); assert.equal(sale.allocations[TOKEN_ONE_INDEX], 0); assert.equal(sale.allocations[TOKEN_TWO_INDEX], 0); @@ -3179,43 +2505,31 @@ contract("ICCO", function(accounts) { assert.ok(!sale.isAborted); // verify getsaleAcceptedTokenInfo getter - const tokenOneInfo = await initialized.methods - .getSaleAcceptedTokenInfo(SALE_3_ID, TOKEN_ONE_INDEX) - .call(); - const tokenTwoInfo = await initialized.methods - .getSaleAcceptedTokenInfo(SALE_3_ID, TOKEN_TWO_INDEX) - .call(); + const tokenOneInfo = await initialized.methods.getSaleAcceptedTokenInfo(SALE_3_ID, TOKEN_ONE_INDEX).call(); + const tokenTwoInfo = await initialized.methods.getSaleAcceptedTokenInfo(SALE_3_ID, TOKEN_TWO_INDEX).call(); assert.equal( tokenOneInfo.tokenAddress.substring(2), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address).substring(2) ); assert.equal(tokenOneInfo.tokenChainId, TEST_CHAIN_ID); assert.equal(tokenOneInfo.conversionRate, tokenOneConversionRate); assert.equal( tokenTwoInfo.tokenAddress.substring(2), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address).substring(2) ); assert.equal(tokenTwoInfo.tokenChainId, TEST_CHAIN_ID); assert.equal(tokenTwoInfo.conversionRate, tokenTwoConversionRate); // verify getSaleTimeFrame getter - const saleTimeframe = await initialized.methods - .getSaleTimeframe(SALE_3_ID) - .call(); + const saleTimeframe = await initialized.methods.getSaleTimeframe(SALE_3_ID).call(); assert.equal(saleTimeframe.start, SALE_3_START); assert.equal(saleTimeframe.end, SALE_3_END); assert.equal(saleTimeframe.unlockTimestamp, SALE_3_END); // verify getSaleStatus getter - const saleStatus = await initialized.methods - .getSaleStatus(SALE_3_ID) - .call(); + const saleStatus = await initialized.methods.getSaleStatus(SALE_3_ID).call(); assert.ok(!saleStatus.isSealed); assert.ok(!saleStatus.isAborted); @@ -3229,10 +2543,7 @@ contract("ICCO", function(accounts) { const refundRecipient = accounts[0]; const expectedRefundRecipientBalanceChange = "1000"; - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); // verify getSaleStatus getter before aborting const saleStatusBefore = await initialized.methods.sales(SALE_3_ID).call(); @@ -3259,33 +2570,25 @@ contract("ICCO", function(accounts) { assert.ok(failed); // balance check before aborting the sale - const refundRecipientBalanceBefore = await SOLD_TOKEN.balanceOf( - refundRecipient - ); + const refundRecipientBalanceBefore = await SOLD_TOKEN.balanceOf(refundRecipient); // abort the sale - const abortTx = await initialized.methods - .abortSaleBeforeStartTime(SALE_3_ID) - .send({ - from: SELLER, // must be the sale initiator (msg.sender in createSale()) - value: WORMHOLE_FEE, - gasLimit: GAS_LIMIT, - }); + const abortTx = await initialized.methods.abortSaleBeforeStartTime(SALE_3_ID).send({ + from: SELLER, // must be the sale initiator (msg.sender in createSale()) + value: WORMHOLE_FEE, + gasLimit: GAS_LIMIT, + }); // confirm that the EventAbortSaleBeforeStart event was emitted - const eventAbort = - abortTx["events"]["EventAbortSaleBeforeStart"]["returnValues"]; + const eventAbort = abortTx["events"]["EventAbortSaleBeforeStart"]["returnValues"]; assert.equal(eventAbort["saleId"], SALE_3_ID); // balance check after aborting the sale - const refundRecipientBalanceAfter = await SOLD_TOKEN.balanceOf( - refundRecipient - ); + const refundRecipientBalanceAfter = await SOLD_TOKEN.balanceOf(refundRecipient); // confirm that the refundRecipient recieved the sale tokens assert.equal( - parseInt(refundRecipientBalanceAfter) - - parseInt(refundRecipientBalanceBefore), + parseInt(refundRecipientBalanceAfter) - parseInt(refundRecipientBalanceBefore), expectedRefundRecipientBalanceChange ); @@ -3311,10 +2614,7 @@ contract("ICCO", function(accounts) { index += 2; // sale id - assert.equal( - parseInt(SALE_SEALED_PAYLOAD_3.substr(index, 64), 16), - SALE_3_ID - ); + assert.equal(parseInt(SALE_SEALED_PAYLOAD_3.substr(index, 64), 16), SALE_3_ID); index += 64; }); @@ -3326,25 +2626,14 @@ contract("ICCO", function(accounts) { const tokenOneContributionAmount = "100"; const tokenTwoContributionAmount = "50"; - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); - await CONTRIBUTED_TOKEN_ONE.approve( - TokenSaleContributor.address, - tokenOneContributionAmount, - { - from: BUYER_ONE, - } - ); - await CONTRIBUTED_TOKEN_TWO.approve( - TokenSaleContributor.address, - tokenTwoContributionAmount, - { - from: BUYER_TWO, - } - ); + await CONTRIBUTED_TOKEN_ONE.approve(TokenSaleContributor.address, tokenOneContributionAmount, { + from: BUYER_ONE, + }); + await CONTRIBUTED_TOKEN_TWO.approve(TokenSaleContributor.address, tokenTwoContributionAmount, { + from: BUYER_TWO, + }); // contribute tokens to the sale const kycSig1 = await signContribution( @@ -3356,12 +2645,7 @@ contract("ICCO", function(accounts) { kycSignerPK ); await initialized.methods - .contribute( - SALE_3_ID, - TOKEN_ONE_INDEX, - parseInt(tokenOneContributionAmount), - kycSig1 - ) + .contribute(SALE_3_ID, TOKEN_ONE_INDEX, parseInt(tokenOneContributionAmount), kycSig1) .send({ from: BUYER_ONE, gasLimit: GAS_LIMIT, @@ -3376,12 +2660,7 @@ contract("ICCO", function(accounts) { kycSignerPK ); await initialized.methods - .contribute( - SALE_3_ID, - TOKEN_TWO_INDEX, - parseInt(tokenTwoContributionAmount), - kycSig2 - ) + .contribute(SALE_3_ID, TOKEN_TWO_INDEX, parseInt(tokenTwoContributionAmount), kycSig2) .send({ from: BUYER_TWO, gasLimit: GAS_LIMIT, @@ -3395,14 +2674,8 @@ contract("ICCO", function(accounts) { .getSaleTotalContribution(SALE_3_ID, TOKEN_TWO_INDEX) .call(); - assert.equal( - totalContributionsTokenOne, - parseInt(tokenOneContributionAmount) - ); - assert.equal( - totalContributionsTokenTwo, - parseInt(tokenTwoContributionAmount) - ); + assert.equal(totalContributionsTokenOne, parseInt(tokenOneContributionAmount)); + assert.equal(totalContributionsTokenTwo, parseInt(tokenTwoContributionAmount)); // verify getSaleContribution const buyerOneContribution = await initialized.methods @@ -3417,15 +2690,10 @@ contract("ICCO", function(accounts) { }); it("contributor should abort third sale correctly", async function() { - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); // verify getSaleStatus before aborting in contributor - const statusBefore = await initialized.methods - .getSaleStatus(SALE_3_ID) - .call(); + const statusBefore = await initialized.methods.getSaleStatus(SALE_3_ID).call(); assert.ok(!statusBefore.isAborted); assert.ok(!statusBefore.isSealed); @@ -3449,9 +2717,7 @@ contract("ICCO", function(accounts) { }); // confirm that saleAborted was set to true - const statusAfter = await initialized.methods - .getSaleStatus(SALE_3_ID) - .call(); + const statusAfter = await initialized.methods.getSaleStatus(SALE_3_ID).call(); assert.ok(statusAfter.isAborted); assert.ok(!statusAfter.isSealed); @@ -3461,18 +2727,11 @@ contract("ICCO", function(accounts) { // test variables const tokenOneContributionAmount = "100"; - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); - await CONTRIBUTED_TOKEN_ONE.approve( - TokenSaleContributor.address, - tokenOneContributionAmount, - { - from: BUYER_ONE, - } - ); + await CONTRIBUTED_TOKEN_ONE.approve(TokenSaleContributor.address, tokenOneContributionAmount, { + from: BUYER_ONE, + }); let failed = false; try { @@ -3486,21 +2745,13 @@ contract("ICCO", function(accounts) { kycSignerPK ); await initialized.methods - .contribute( - SALE_3_ID, - TOKEN_ONE_INDEX, - parseInt(tokenOneContributionAmount), - kycSig1 - ) + .contribute(SALE_3_ID, TOKEN_ONE_INDEX, parseInt(tokenOneContributionAmount), kycSig1) .send({ from: BUYER_ONE, gasLimit: GAS_LIMIT, }); } catch (e) { - assert.equal( - e.message, - "Returned error: VM Exception while processing transaction: revert sale was aborted" - ); + assert.equal(e.message, "Returned error: VM Exception while processing transaction: revert sale was aborted"); failed = true; } @@ -3510,10 +2761,7 @@ contract("ICCO", function(accounts) { it("contributor should not allow contributions to be attested after sale is aborted early", async function() { await wait(10); - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); let failed = false; try { @@ -3544,10 +2792,7 @@ contract("ICCO", function(accounts) { const expectedBuyerOneBalanceAfter = "10000"; const expectedBuyerTwoBalanceAfter = "14900"; - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); // confirm refundIsClaimed is set to false const buyerOneHasClaimedRefundBefore = await initialized.methods @@ -3561,27 +2806,13 @@ contract("ICCO", function(accounts) { assert.ok(!buyerTwoHasClaimedRefundBefore); // check balances of contributed tokens for buyers and the contributor - const actualContributorTokenOneBalanceBefore = await CONTRIBUTED_TOKEN_ONE.balanceOf( - TokenSaleContributor.address - ); - const actualContributorTokenTwoBalanceBefore = await CONTRIBUTED_TOKEN_TWO.balanceOf( - TokenSaleContributor.address - ); - const actualBuyerOneBalanceBefore = await CONTRIBUTED_TOKEN_ONE.balanceOf( - BUYER_ONE - ); - const actualBuyerTwoBalanceBefore = await CONTRIBUTED_TOKEN_TWO.balanceOf( - BUYER_TWO - ); + const actualContributorTokenOneBalanceBefore = await CONTRIBUTED_TOKEN_ONE.balanceOf(TokenSaleContributor.address); + const actualContributorTokenTwoBalanceBefore = await CONTRIBUTED_TOKEN_TWO.balanceOf(TokenSaleContributor.address); + const actualBuyerOneBalanceBefore = await CONTRIBUTED_TOKEN_ONE.balanceOf(BUYER_ONE); + const actualBuyerTwoBalanceBefore = await CONTRIBUTED_TOKEN_TWO.balanceOf(BUYER_TWO); - assert.equal( - actualContributorTokenOneBalanceBefore, - expectedContributorTokenOneBalanceBefore - ); - assert.equal( - actualContributorTokenTwoBalanceBefore, - expectedContributorTokenTwoBalanceBefore - ); + assert.equal(actualContributorTokenOneBalanceBefore, expectedContributorTokenOneBalanceBefore); + assert.equal(actualContributorTokenTwoBalanceBefore, expectedContributorTokenTwoBalanceBefore); assert.equal(actualBuyerOneBalanceBefore, expectedBuyerOneBalanceBefore); assert.equal(actualBuyerTwoBalanceBefore, expectedBuyerTwoBalanceBefore); @@ -3597,27 +2828,13 @@ contract("ICCO", function(accounts) { }); // check balances of contributed tokens for buyers and the contributor - const actualContributorTokenOneBalanceAfter = await CONTRIBUTED_TOKEN_ONE.balanceOf( - TokenSaleContributor.address - ); - const actualContributorTokenTwoBalanceAfter = await CONTRIBUTED_TOKEN_TWO.balanceOf( - TokenSaleContributor.address - ); - const actualBuyerOneBalanceAfter = await CONTRIBUTED_TOKEN_ONE.balanceOf( - BUYER_ONE - ); - const actualBuyerTwoBalanceAfter = await CONTRIBUTED_TOKEN_TWO.balanceOf( - BUYER_TWO - ); + const actualContributorTokenOneBalanceAfter = await CONTRIBUTED_TOKEN_ONE.balanceOf(TokenSaleContributor.address); + const actualContributorTokenTwoBalanceAfter = await CONTRIBUTED_TOKEN_TWO.balanceOf(TokenSaleContributor.address); + const actualBuyerOneBalanceAfter = await CONTRIBUTED_TOKEN_ONE.balanceOf(BUYER_ONE); + const actualBuyerTwoBalanceAfter = await CONTRIBUTED_TOKEN_TWO.balanceOf(BUYER_TWO); - assert.equal( - actualContributorTokenOneBalanceAfter, - expectedContributorTokenOneBalanceAfter - ); - assert.equal( - actualContributorTokenTwoBalanceAfter, - expectedContributorTokenTwoBalanceAfter - ); + assert.equal(actualContributorTokenOneBalanceAfter, expectedContributorTokenOneBalanceAfter); + assert.equal(actualContributorTokenTwoBalanceAfter, expectedContributorTokenTwoBalanceAfter); assert.equal(actualBuyerOneBalanceAfter, expectedBuyerOneBalanceAfter); assert.equal(actualBuyerTwoBalanceAfter, expectedBuyerTwoBalanceAfter); @@ -3665,10 +2882,7 @@ contract("ICCO", function(accounts) { await SOLD_TOKEN.mint(SELLER, saleTokenMintAmount); await SOLD_TOKEN.approve(TokenSaleConductor.address, saleTokenAmount); - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); // create array (struct) for sale params const saleParams = [ @@ -3689,16 +2903,8 @@ contract("ICCO", function(accounts) { // create accepted tokens array const acceptedTokens = [ - [ - TEST_CHAIN_ID, - "0x000000000000000000000000" + CONTRIBUTED_TOKEN_ONE.address.substr(2), - tokenOneConversionRate, - ], - [ - TEST_CHAIN_ID, - "0x000000000000000000000000" + CONTRIBUTED_TOKEN_TWO.address.substr(2), - tokenTwoConversionRate, - ], + [TEST_CHAIN_ID, "0x000000000000000000000000" + CONTRIBUTED_TOKEN_ONE.address.substr(2), tokenOneConversionRate], + [TEST_CHAIN_ID, "0x000000000000000000000000" + CONTRIBUTED_TOKEN_TWO.address.substr(2), tokenTwoConversionRate], ]; // create the sale @@ -3738,17 +2944,12 @@ contract("ICCO", function(accounts) { // token chain assert.equal( log.payload.substr(index, 4), - web3.eth.abi - .encodeParameter("uint16", TEST_CHAIN_ID) - .substring(2 + 64 - 4) + web3.eth.abi.encodeParameter("uint16", TEST_CHAIN_ID).substring(2 + 64 - 4) ); index += 4; // token decimals - assert.equal( - parseInt(log.payload.substr(index, 2), 16), - SOLD_TOKEN_DECIMALS - ); + assert.equal(parseInt(log.payload.substr(index, 2), 16), SOLD_TOKEN_DECIMALS); index += 2; // timestamp start @@ -3760,74 +2961,51 @@ contract("ICCO", function(accounts) { index += 64; // accepted tokens length - assert.equal( - parseInt(log.payload.substr(index, 2), 16), - acceptedTokenLength - ); + assert.equal(parseInt(log.payload.substr(index, 2), 16), acceptedTokenLength); index += 2; // token address assert.equal( log.payload.substr(index, 64), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address).substring(2) ); index += 64; // token chain assert.equal( log.payload.substr(index, 4), - web3.eth.abi - .encodeParameter("uint16", TEST_CHAIN_ID) - .substring(2 + 64 - 4) + web3.eth.abi.encodeParameter("uint16", TEST_CHAIN_ID).substring(2 + 64 - 4) ); index += 4; // conversion rate - assert.equal( - parseInt(log.payload.substr(index, 32), 16), - parseInt(tokenOneConversionRate) - ); + assert.equal(parseInt(log.payload.substr(index, 32), 16), parseInt(tokenOneConversionRate)); index += 32; // token address assert.equal( log.payload.substr(index, 64), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address).substring(2) ); index += 64; // token chain assert.equal( log.payload.substr(index, 4), - web3.eth.abi - .encodeParameter("uint16", TEST_CHAIN_ID) - .substring(2 + 64 - 4) + web3.eth.abi.encodeParameter("uint16", TEST_CHAIN_ID).substring(2 + 64 - 4) ); index += 4; // conversion rate - assert.equal( - parseInt(log.payload.substr(index, 32), 16), - parseInt(tokenTwoConversionRate) - ); + assert.equal(parseInt(log.payload.substr(index, 32), 16), parseInt(tokenTwoConversionRate)); index += 32; // recipient of proceeds - assert.equal( - log.payload.substr(index, 64), - web3.eth.abi.encodeParameter("address", saleRecipient).substring(2) - ); + assert.equal(log.payload.substr(index, 64), web3.eth.abi.encodeParameter("address", saleRecipient).substring(2)); index += 64; // KYC authority public key - assert.equal( - log.payload.substr(index, 40), - web3.eth.abi.encodeParameter("address", KYC_AUTHORITY).substring(26) - ); + assert.equal(log.payload.substr(index, 40), web3.eth.abi.encodeParameter("address", KYC_AUTHORITY).substring(26)); index += 40; // unlock timestamp @@ -3854,10 +3032,7 @@ contract("ICCO", function(accounts) { const tokenTwoConversionRate = "4000000000000000000"; const saleRecipient = accounts[0]; - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); const vm = await signAndEncodeVM( 1, @@ -3891,30 +3066,17 @@ contract("ICCO", function(accounts) { assert.equal(sale.unlockTimestamp, SALE_4_END); assert.equal( sale.acceptedTokensAddresses[TOKEN_ONE_INDEX].substring(2), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address).substring(2) ); assert.equal(sale.acceptedTokensChains[TOKEN_ONE_INDEX], TEST_CHAIN_ID); - assert.equal( - sale.acceptedTokensConversionRates[TOKEN_ONE_INDEX], - tokenOneConversionRate - ); + assert.equal(sale.acceptedTokensConversionRates[TOKEN_ONE_INDEX], tokenOneConversionRate); assert.equal( sale.acceptedTokensAddresses[TOKEN_TWO_INDEX].substring(2), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address).substring(2) ); assert.equal(sale.acceptedTokensChains[TOKEN_TWO_INDEX], TEST_CHAIN_ID); - assert.equal( - sale.acceptedTokensConversionRates[TOKEN_TWO_INDEX], - tokenTwoConversionRate - ); - assert.equal( - sale.recipient.substring(2), - web3.eth.abi.encodeParameter("address", saleRecipient).substring(2) - ); + assert.equal(sale.acceptedTokensConversionRates[TOKEN_TWO_INDEX], tokenTwoConversionRate); + assert.equal(sale.recipient.substring(2), web3.eth.abi.encodeParameter("address", saleRecipient).substring(2)); assert.equal(sale.authority.substring(2), KYC_AUTHORITY.substring(2)); assert.equal(sale.allocations[TOKEN_ONE_INDEX], 0); assert.equal(sale.allocations[TOKEN_TWO_INDEX], 0); @@ -3924,43 +3086,31 @@ contract("ICCO", function(accounts) { assert.ok(!sale.isAborted); // verify getsaleAcceptedTokenInfo getter - const tokenOneInfo = await initialized.methods - .getSaleAcceptedTokenInfo(SALE_4_ID, TOKEN_ONE_INDEX) - .call(); - const tokenTwoInfo = await initialized.methods - .getSaleAcceptedTokenInfo(SALE_4_ID, TOKEN_TWO_INDEX) - .call(); + const tokenOneInfo = await initialized.methods.getSaleAcceptedTokenInfo(SALE_4_ID, TOKEN_ONE_INDEX).call(); + const tokenTwoInfo = await initialized.methods.getSaleAcceptedTokenInfo(SALE_4_ID, TOKEN_TWO_INDEX).call(); assert.equal( tokenOneInfo.tokenAddress.substring(2), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address).substring(2) ); assert.equal(tokenOneInfo.tokenChainId, TEST_CHAIN_ID); assert.equal(tokenOneInfo.conversionRate, tokenOneConversionRate); assert.equal( tokenTwoInfo.tokenAddress.substring(2), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address).substring(2) ); assert.equal(tokenTwoInfo.tokenChainId, TEST_CHAIN_ID); assert.equal(tokenTwoInfo.conversionRate, tokenTwoConversionRate); // verify getSaleTimeFrame getter - const saleTimeframe = await initialized.methods - .getSaleTimeframe(SALE_4_ID) - .call(); + const saleTimeframe = await initialized.methods.getSaleTimeframe(SALE_4_ID).call(); assert.equal(saleTimeframe.start, SALE_4_START); assert.equal(saleTimeframe.end, SALE_4_END); assert.equal(saleTimeframe.unlockTimestamp, SALE_4_END); // verify getSaleStatus getter - const saleStatus = await initialized.methods - .getSaleStatus(SALE_4_ID) - .call(); + const saleStatus = await initialized.methods.getSaleStatus(SALE_4_ID).call(); assert.ok(!saleStatus.isSealed); assert.ok(!saleStatus.isAborted); @@ -3973,34 +3123,22 @@ contract("ICCO", function(accounts) { const tokenOneContributionAmount = ["2000", "4000"]; const tokenTwoContributionAmount = ["500", "500"]; - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); // approve contribution amounts await CONTRIBUTED_TOKEN_ONE.approve( TokenSaleContributor.address, - parseInt(tokenOneContributionAmount[0]) + - parseInt(tokenOneContributionAmount[1]), - { - from: BUYER_ONE, - } - ); - await CONTRIBUTED_TOKEN_TWO.approve( - TokenSaleContributor.address, - tokenTwoContributionAmount[0], - { - from: BUYER_TWO, - } - ); - await CONTRIBUTED_TOKEN_TWO.approve( - TokenSaleContributor.address, - tokenTwoContributionAmount[1], + parseInt(tokenOneContributionAmount[0]) + parseInt(tokenOneContributionAmount[1]), { from: BUYER_ONE, } ); + await CONTRIBUTED_TOKEN_TWO.approve(TokenSaleContributor.address, tokenTwoContributionAmount[0], { + from: BUYER_TWO, + }); + await CONTRIBUTED_TOKEN_TWO.approve(TokenSaleContributor.address, tokenTwoContributionAmount[1], { + from: BUYER_ONE, + }); // perform "kyc" and contribute tokens to the sale for BUYER_ONE const kycSig1 = await signContribution( @@ -4012,12 +3150,7 @@ contract("ICCO", function(accounts) { kycSignerPK ); await initialized.methods - .contribute( - SALE_4_ID, - TOKEN_ONE_INDEX, - parseInt(tokenOneContributionAmount[0]), - kycSig1 - ) + .contribute(SALE_4_ID, TOKEN_ONE_INDEX, parseInt(tokenOneContributionAmount[0]), kycSig1) .send({ from: BUYER_ONE, gasLimit: GAS_LIMIT, @@ -4032,12 +3165,7 @@ contract("ICCO", function(accounts) { kycSignerPK ); await initialized.methods - .contribute( - SALE_4_ID, - TOKEN_ONE_INDEX, - parseInt(tokenOneContributionAmount[1]), - kycSig2 - ) + .contribute(SALE_4_ID, TOKEN_ONE_INDEX, parseInt(tokenOneContributionAmount[1]), kycSig2) .send({ from: BUYER_ONE, gasLimit: GAS_LIMIT, @@ -4052,12 +3180,7 @@ contract("ICCO", function(accounts) { kycSignerPK ); await initialized.methods - .contribute( - SALE_4_ID, - TOKEN_TWO_INDEX, - parseInt(tokenTwoContributionAmount[1]), - kycSig3 - ) + .contribute(SALE_4_ID, TOKEN_TWO_INDEX, parseInt(tokenTwoContributionAmount[1]), kycSig3) .send({ from: BUYER_ONE, gasLimit: GAS_LIMIT, @@ -4073,12 +3196,7 @@ contract("ICCO", function(accounts) { kycSignerPK ); await initialized.methods - .contribute( - SALE_4_ID, - TOKEN_TWO_INDEX, - parseInt(tokenTwoContributionAmount[0]), - kycSig4 - ) + .contribute(SALE_4_ID, TOKEN_TWO_INDEX, parseInt(tokenTwoContributionAmount[0]), kycSig4) .send({ from: BUYER_TWO, gasLimit: GAS_LIMIT, @@ -4094,13 +3212,11 @@ contract("ICCO", function(accounts) { assert.equal( totalContributionsTokenOne, - parseInt(tokenOneContributionAmount[0]) + - parseInt(tokenOneContributionAmount[1]) + parseInt(tokenOneContributionAmount[0]) + parseInt(tokenOneContributionAmount[1]) ); assert.equal( totalContributionsTokenTwo, - parseInt(tokenTwoContributionAmount[0]) + - parseInt(tokenTwoContributionAmount[1]) + parseInt(tokenTwoContributionAmount[0]) + parseInt(tokenTwoContributionAmount[1]) ); // verify getSaleContribution @@ -4116,13 +3232,9 @@ contract("ICCO", function(accounts) { assert.equal( buyerOneContributionTokenOne, - parseInt(tokenOneContributionAmount[0]) + - parseInt(tokenOneContributionAmount[1]) - ); - assert.equal( - buyerOneContributionTokenTwo, - parseInt(tokenTwoContributionAmount[1]) + parseInt(tokenOneContributionAmount[0]) + parseInt(tokenOneContributionAmount[1]) ); + assert.equal(buyerOneContributionTokenTwo, parseInt(tokenTwoContributionAmount[1])); assert.equal(buyerTwoContribution, parseInt(tokenTwoContributionAmount[0])); }); @@ -4137,10 +3249,7 @@ contract("ICCO", function(accounts) { const acceptedTokenLength = "2"; const payloadIdType2 = "02"; - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); // attest contributions await initialized.methods.attestContributions(SALE_4_ID).send({ @@ -4167,45 +3276,27 @@ contract("ICCO", function(accounts) { index += 64; // chain id - assert.equal( - log.payload.substr(index, 4), - web3.eth.abi.encodeParameter("uint16", 2).substring(2 + 64 - 4) - ); + assert.equal(log.payload.substr(index, 4), web3.eth.abi.encodeParameter("uint16", 2).substring(2 + 64 - 4)); index += 4; // tokens length - assert.equal( - parseInt(log.payload.substr(index, 2), 16), - acceptedTokenLength - ); + assert.equal(parseInt(log.payload.substr(index, 2), 16), acceptedTokenLength); index += 2; // token index - assert.equal( - log.payload.substr(index, 2), - web3.eth.abi.encodeParameter("uint8", 0).substring(2 + 64 - 2) - ); + assert.equal(log.payload.substr(index, 2), web3.eth.abi.encodeParameter("uint8", 0).substring(2 + 64 - 2)); index += 2; // amount - assert.equal( - parseInt(log.payload.substr(index, 64), 16), - tokenOneContributionAmount - ); + assert.equal(parseInt(log.payload.substr(index, 64), 16), tokenOneContributionAmount); index += 64; // token index - assert.equal( - log.payload.substr(index, 2), - web3.eth.abi.encodeParameter("uint8", 1).substring(2 + 64 - 2) - ); + assert.equal(log.payload.substr(index, 2), web3.eth.abi.encodeParameter("uint8", 1).substring(2 + 64 - 2)); index += 2; // amount - assert.equal( - parseInt(log.payload.substr(index, 64), 16), - tokenTwoContributionAmount - ); + assert.equal(parseInt(log.payload.substr(index, 64), 16), tokenTwoContributionAmount); index += 64; assert.equal(log.payload.length, index); @@ -4218,10 +3309,7 @@ contract("ICCO", function(accounts) { const tokenOneContributionAmount = "6000"; // both contributions const tokenTwoContributionAmount = "1000"; - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); // verify saleContributionIsCollected getter before collecting contributions const isContributionOneCollectedBefore = await initialized.methods @@ -4263,9 +3351,7 @@ contract("ICCO", function(accounts) { assert.ok(isContributionTwoCollectedAfter); // verify saleContributions getter - const contributions = await initialized.methods - .saleContributions(SALE_4_ID) - .call(); + const contributions = await initialized.methods.saleContributions(SALE_4_ID).call(); assert.equal(contributions[0], tokenOneContributionAmount); assert.equal(contributions[1], tokenTwoContributionAmount); @@ -4281,22 +3367,12 @@ contract("ICCO", function(accounts) { const expectedConductorBalanceAfter = "0"; const payloadIdType3 = "03"; - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); - const actualContributorBalanceBefore = await SOLD_TOKEN.balanceOf( - TokenSaleContributor.address - ); - const actualConductorBalanceBefore = await SOLD_TOKEN.balanceOf( - TokenSaleConductor.address - ); + const actualContributorBalanceBefore = await SOLD_TOKEN.balanceOf(TokenSaleContributor.address); + const actualConductorBalanceBefore = await SOLD_TOKEN.balanceOf(TokenSaleConductor.address); - assert.equal( - actualContributorBalanceBefore, - expectedContributorBalanceBefore - ); + assert.equal(actualContributorBalanceBefore, expectedContributorBalanceBefore); assert.equal(actualConductorBalanceBefore, expectedConductorBalanceBefore); // verify sealSealed flag in sales @@ -4316,17 +3392,10 @@ contract("ICCO", function(accounts) { assert.equal(eventSeal["saleId"], SALE_4_ID); // balance check - const actualContributorBalanceAfter = await SOLD_TOKEN.balanceOf( - TokenSaleContributor.address - ); - const actualConductorBalanceAfter = await SOLD_TOKEN.balanceOf( - TokenSaleConductor.address - ); + const actualContributorBalanceAfter = await SOLD_TOKEN.balanceOf(TokenSaleContributor.address); + const actualConductorBalanceAfter = await SOLD_TOKEN.balanceOf(TokenSaleConductor.address); - assert.equal( - actualContributorBalanceAfter, - expectedContributorBalanceAfter - ); + assert.equal(actualContributorBalanceAfter, expectedContributorBalanceAfter); assert.equal(actualConductorBalanceAfter, expectedConductorBalanceAfter); const log = ( @@ -4364,18 +3433,11 @@ contract("ICCO", function(accounts) { const expectedRecipientTokenOneBalanceChange = "3600"; const expectedRecipientTokenTwoBalanceChange = "600"; - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); // grab contributed token balance before for sale recipient - const receipientTokenOneBalanceBefore = await CONTRIBUTED_TOKEN_ONE.balanceOf( - SELLER - ); - const receipientTokenTwoBalanceBefore = await CONTRIBUTED_TOKEN_TWO.balanceOf( - SELLER - ); + const receipientTokenOneBalanceBefore = await CONTRIBUTED_TOKEN_ONE.balanceOf(SELLER); + const receipientTokenTwoBalanceBefore = await CONTRIBUTED_TOKEN_TWO.balanceOf(SELLER); // verify sealSealed getters before calling saleSealed const saleBefore = await initialized.methods.sales(SALE_4_ID).call(); @@ -4407,34 +3469,22 @@ contract("ICCO", function(accounts) { assert.ok(saleAfter.isSealed); // verify getSaleAllocation after sealing the sale - const actualAllocationTokenOne = await initialized.methods - .getSaleAllocation(SALE_4_ID, TOKEN_ONE_INDEX) - .call(); - const actualAllocationTokenTwo = await initialized.methods - .getSaleAllocation(SALE_4_ID, TOKEN_TWO_INDEX) - .call(); + const actualAllocationTokenOne = await initialized.methods.getSaleAllocation(SALE_4_ID, TOKEN_ONE_INDEX).call(); + const actualAllocationTokenTwo = await initialized.methods.getSaleAllocation(SALE_4_ID, TOKEN_TWO_INDEX).call(); assert.equal(actualAllocationTokenOne, expectedAllocationTokenOne); assert.equal(actualAllocationTokenTwo, expectedAllocationTokenTwo); // verify getSaleExcessContribution after sealing the sale - const actualExcessTokenOne = await initialized.methods - .getSaleExcessContribution(SALE_4_ID, TOKEN_ONE_INDEX) - .call(); - const actualExcessTokenTwo = await initialized.methods - .getSaleExcessContribution(SALE_4_ID, TOKEN_TWO_INDEX) - .call(); + const actualExcessTokenOne = await initialized.methods.getSaleExcessContribution(SALE_4_ID, TOKEN_ONE_INDEX).call(); + const actualExcessTokenTwo = await initialized.methods.getSaleExcessContribution(SALE_4_ID, TOKEN_TWO_INDEX).call(); assert.equal(actualExcessTokenOne, expectedExcessTokenOne); assert.equal(actualExcessTokenTwo, expectedExcessTokenTwo); // confirm that the sale recipient recieved the correct amount of contributions - const receipientTokenOneBalanceAfter = await CONTRIBUTED_TOKEN_ONE.balanceOf( - SELLER - ); - const receipientTokenTwoBalanceAfter = await CONTRIBUTED_TOKEN_TWO.balanceOf( - SELLER - ); + const receipientTokenOneBalanceAfter = await CONTRIBUTED_TOKEN_ONE.balanceOf(SELLER); + const receipientTokenTwoBalanceAfter = await CONTRIBUTED_TOKEN_TWO.balanceOf(SELLER); assert.equal( receipientTokenOneBalanceAfter - receipientTokenOneBalanceBefore, @@ -4452,21 +3502,12 @@ contract("ICCO", function(accounts) { const expectedBuyerOneSaleTokenBalanceChange = "800"; // 80% of total contribution (2000 * 1 + 4000 * 1 + 500 * 4 = 8000) const expectedBuyerTwoSaleTokenBalanceChange = "200"; // 20% of total contribution (500 * 4 = 2000) - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); // check balances before claiming allocations and excess contributions - const contributorSaleTokenBalanceBefore = await SOLD_TOKEN.balanceOf( - TokenSaleContributor.address - ); - const buyerOneSaleTokenBalanceBefore = await SOLD_TOKEN.balanceOf( - BUYER_ONE - ); - const buyerTwoSaleTokenBalanceBefore = await SOLD_TOKEN.balanceOf( - BUYER_TWO - ); + const contributorSaleTokenBalanceBefore = await SOLD_TOKEN.balanceOf(TokenSaleContributor.address); + const buyerOneSaleTokenBalanceBefore = await SOLD_TOKEN.balanceOf(BUYER_ONE); + const buyerTwoSaleTokenBalanceBefore = await SOLD_TOKEN.balanceOf(BUYER_TWO); // verify allocationIsClaimed before claiming allocation const isAllocationClaimedBuyerOneTokenOneBefore = await initialized.methods @@ -4500,9 +3541,7 @@ contract("ICCO", function(accounts) { }); // check that sale token allocations were distributed correctly - const contributorSaleTokenBalanceAfter = await SOLD_TOKEN.balanceOf( - TokenSaleContributor.address - ); + const contributorSaleTokenBalanceAfter = await SOLD_TOKEN.balanceOf(TokenSaleContributor.address); const buyerOneSaleTokenBalanceAfter = await SOLD_TOKEN.balanceOf(BUYER_ONE); const buyerTwoSaleTokenBalanceAfter = await SOLD_TOKEN.balanceOf(BUYER_TWO); @@ -4544,21 +3583,12 @@ contract("ICCO", function(accounts) { const expectedBuyerOneTokenTwoRefund = "200"; // .2 * 4k / 4 (multiplier) const expectedBuyerTwoTokenTwoRefund = "200"; // .2 * 4k / 4 (multiplier) - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); // balances of contributed tokens - const buyerOneTokenOneBalanceBefore = await CONTRIBUTED_TOKEN_ONE.balanceOf( - BUYER_ONE - ); - const buyerOneTokenTwoBalanceBefore = await CONTRIBUTED_TOKEN_TWO.balanceOf( - BUYER_ONE - ); - const buyerTwoTokenTwoBalanceBefore = await CONTRIBUTED_TOKEN_TWO.balanceOf( - BUYER_TWO - ); + const buyerOneTokenOneBalanceBefore = await CONTRIBUTED_TOKEN_ONE.balanceOf(BUYER_ONE); + const buyerOneTokenTwoBalanceBefore = await CONTRIBUTED_TOKEN_TWO.balanceOf(BUYER_ONE); + const buyerTwoTokenTwoBalanceBefore = await CONTRIBUTED_TOKEN_TWO.balanceOf(BUYER_TWO); // verify excessContributionIsClaimed before claiming excessContributions const isExcessClaimedBuyerOneTokenOneBefore = await initialized.methods @@ -4577,58 +3607,37 @@ contract("ICCO", function(accounts) { // claim excess refunds here // claim allocations for both tokens - await initialized.methods - .claimExcessContribution(SALE_4_ID, TOKEN_ONE_INDEX) - .send({ - from: BUYER_ONE, - gasLimit: GAS_LIMIT, - }); + await initialized.methods.claimExcessContribution(SALE_4_ID, TOKEN_ONE_INDEX).send({ + from: BUYER_ONE, + gasLimit: GAS_LIMIT, + }); ONE_EXCESS_REFUND_SNAPSHOT = await snapshot(); - await initialized.methods - .claimExcessContribution(SALE_4_ID, TOKEN_TWO_INDEX) - .send({ - from: BUYER_ONE, - gasLimit: GAS_LIMIT, - }); + await initialized.methods.claimExcessContribution(SALE_4_ID, TOKEN_TWO_INDEX).send({ + from: BUYER_ONE, + gasLimit: GAS_LIMIT, + }); - const claimExcessTx = await initialized.methods - .claimExcessContribution(SALE_4_ID, TOKEN_TWO_INDEX) - .send({ - from: BUYER_TWO, - gasLimit: GAS_LIMIT, - }); + const claimExcessTx = await initialized.methods.claimExcessContribution(SALE_4_ID, TOKEN_TWO_INDEX).send({ + from: BUYER_TWO, + gasLimit: GAS_LIMIT, + }); // confirm that the EventClaimExcessContribution event was emitted - const eventClaimExcess = - claimExcessTx["events"]["EventClaimExcessContribution"]["returnValues"]; + const eventClaimExcess = claimExcessTx["events"]["EventClaimExcessContribution"]["returnValues"]; assert.equal(eventClaimExcess["saleId"], SALE_4_ID); assert.equal(eventClaimExcess["tokenIndex"], TOKEN_TWO_INDEX); + assert.equal(eventClaimExcess["amount"], expectedBuyerTwoTokenTwoRefund); // check that excess contributions were distributed correctly - const buyerOneTokenOneBalanceAfter = await CONTRIBUTED_TOKEN_ONE.balanceOf( - BUYER_ONE - ); - const buyerOneTokenTwoBalanceAfter = await CONTRIBUTED_TOKEN_TWO.balanceOf( - BUYER_ONE - ); - const buyerTwoTokenTwoBalanceAfter = await CONTRIBUTED_TOKEN_TWO.balanceOf( - BUYER_TWO - ); + const buyerOneTokenOneBalanceAfter = await CONTRIBUTED_TOKEN_ONE.balanceOf(BUYER_ONE); + const buyerOneTokenTwoBalanceAfter = await CONTRIBUTED_TOKEN_TWO.balanceOf(BUYER_ONE); + const buyerTwoTokenTwoBalanceAfter = await CONTRIBUTED_TOKEN_TWO.balanceOf(BUYER_TWO); - assert.equal( - buyerOneTokenOneBalanceAfter - buyerOneTokenOneBalanceBefore, - expectedBuyerOneTokenOneRefund - ); - assert.equal( - buyerOneTokenTwoBalanceAfter - buyerOneTokenTwoBalanceBefore, - expectedBuyerOneTokenTwoRefund - ); - assert.equal( - buyerTwoTokenTwoBalanceAfter - buyerTwoTokenTwoBalanceBefore, - expectedBuyerTwoTokenTwoRefund - ); + assert.equal(buyerOneTokenOneBalanceAfter - buyerOneTokenOneBalanceBefore, expectedBuyerOneTokenOneRefund); + assert.equal(buyerOneTokenTwoBalanceAfter - buyerOneTokenTwoBalanceBefore, expectedBuyerOneTokenTwoRefund); + assert.equal(buyerTwoTokenTwoBalanceAfter - buyerTwoTokenTwoBalanceBefore, expectedBuyerTwoTokenTwoRefund); // verify excessContributionIsClaimed after claiming excessContributions const isExcessClaimedBuyerOneTokenOneAfter = await initialized.methods @@ -4650,19 +3659,14 @@ contract("ICCO", function(accounts) { // revert first excessContribution claim await revert(ONE_EXCESS_REFUND_SNAPSHOT); - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); let failed = false; try { - await initialized.methods - .claimExcessContribution(SALE_4_ID, TOKEN_ONE_INDEX) - .send({ - from: BUYER_ONE, - gasLimit: GAS_LIMIT, - }); + await initialized.methods.claimExcessContribution(SALE_4_ID, TOKEN_ONE_INDEX).send({ + from: BUYER_ONE, + gasLimit: GAS_LIMIT, + }); } catch (e) { assert.equal( e.message, @@ -4683,9 +3687,7 @@ contract("ICCO", function(accounts) { let ETH_TOKEN_INDEX; it("create a fifth sale correctly and attest over wormhole", async function() { - console.log( - "\n -------------------------- Sale Test #5 (Sale With Solana Token) --------------------------" - ); + console.log("\n -------------------------- Sale Test #5 (Sale With Solana Token) --------------------------"); // test variables const current_block = await web3.eth.getBlock("latest"); @@ -4710,10 +3712,7 @@ contract("ICCO", function(accounts) { await SOLD_TOKEN.mint(SELLER, saleTokenAmount); await SOLD_TOKEN.approve(TokenSaleConductor.address, saleTokenAmount); - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); // need to register a contributor contract const solanaContributorAddress = web3.eth.abi.encodeParameter( @@ -4761,13 +3760,11 @@ contract("ICCO", function(accounts) { let failed = false; try { // attest contributions - await initialized.methods - .createSale(saleParams, testAcceptedTokens) - .send({ - value: WORMHOLE_FEE * 2, - from: SELLER, - gasLimit: GAS_LIMIT, - }); + await initialized.methods.createSale(saleParams, testAcceptedTokens).send({ + value: WORMHOLE_FEE * 2, + from: SELLER, + gasLimit: GAS_LIMIT, + }); } catch (e) { assert.equal( e.message, @@ -4780,11 +3777,7 @@ contract("ICCO", function(accounts) { // create accepted tokens array const acceptedTokens = [ - [ - TEST_CHAIN_ID, - "0x000000000000000000000000" + CONTRIBUTED_TOKEN_TWO.address.substr(2), - tokenTwoConversionRate, - ], + [TEST_CHAIN_ID, "0x000000000000000000000000" + CONTRIBUTED_TOKEN_TWO.address.substr(2), tokenTwoConversionRate], [ SOLANA_CHAIN_ID, "0x000000000000000000000000" + CONTRIBUTED_TOKEN_ONE.address.substr(2), // placeholder address @@ -4834,17 +3827,12 @@ contract("ICCO", function(accounts) { // token chain assert.equal( log.payload.substr(index, 4), - web3.eth.abi - .encodeParameter("uint16", TEST_CHAIN_ID) - .substring(2 + 64 - 4) + web3.eth.abi.encodeParameter("uint16", TEST_CHAIN_ID).substring(2 + 64 - 4) ); index += 4; // token decimals - assert.equal( - parseInt(log.payload.substr(index, 2), 16), - SOLD_TOKEN_DECIMALS - ); + assert.equal(parseInt(log.payload.substr(index, 2), 16), SOLD_TOKEN_DECIMALS); index += 2; // timestamp start @@ -4856,56 +3844,37 @@ contract("ICCO", function(accounts) { index += 64; // accepted tokens length - assert.equal( - parseInt(log.payload.substr(index, 2), 16), - solanaAcceptedTokensLength - ); + assert.equal(parseInt(log.payload.substr(index, 2), 16), solanaAcceptedTokensLength); index += 2; // accepted token index - assert.equal( - parseInt(log.payload.substr(index, 2), 16), - SOLANA_TOKEN_INDEX_ONE - ); + assert.equal(parseInt(log.payload.substr(index, 2), 16), SOLANA_TOKEN_INDEX_ONE); index += 2; // token address assert.equal( log.payload.substr(index, 64), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_ONE.address).substring(2) ); index += 64; // accepted token index - assert.equal( - parseInt(log.payload.substr(index, 2), 16), - SOLANA_TOKEN_INDEX_TWO - ); + assert.equal(parseInt(log.payload.substr(index, 2), 16), SOLANA_TOKEN_INDEX_TWO); index += 2; // token address assert.equal( log.payload.substr(index, 64), - web3.eth.abi - .encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address) - .substring(2) + web3.eth.abi.encodeParameter("address", CONTRIBUTED_TOKEN_TWO.address).substring(2) ); index += 64; // recipient of proceeds - assert.equal( - log.payload.substr(index, 64), - web3.eth.abi.encodeParameter("address", saleRecipient).substring(2) - ); + assert.equal(log.payload.substr(index, 64), web3.eth.abi.encodeParameter("address", saleRecipient).substring(2)); index += 64; // KYC authority public key - assert.equal( - log.payload.substr(index, 40), - web3.eth.abi.encodeParameter("address", KYC_AUTHORITY).substring(26) - ); + assert.equal(log.payload.substr(index, 40), web3.eth.abi.encodeParameter("address", KYC_AUTHORITY).substring(26)); index += 40; // unlock timestamp @@ -4932,35 +3901,18 @@ contract("ICCO", function(accounts) { const acceptedTokensLengthSolana = 2; const acceptedTokensLengthEthereum = 1; - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); // construct contributions payload coming from Solana contributor const solanaContributionsSealed = [ - web3.eth.abi - .encodeParameter("uint8", payloadIdType2) - .substring(2 + (64 - 2)), + web3.eth.abi.encodeParameter("uint8", payloadIdType2).substring(2 + (64 - 2)), web3.eth.abi.encodeParameter("uint256", SALE_5_ID).substring(2), - web3.eth.abi - .encodeParameter("uint16", SOLANA_CHAIN_ID) - .substring(2 + (64 - 4)), - web3.eth.abi - .encodeParameter("uint8", acceptedTokensLengthSolana) - .substring(2 + (64 - 2)), - web3.eth.abi - .encodeParameter("uint8", SOLANA_TOKEN_INDEX_ONE) - .substring(2 + (64 - 2)), - web3.eth.abi - .encodeParameter("uint256", solanaTokenContribution) - .substring(2), - web3.eth.abi - .encodeParameter("uint8", SOLANA_TOKEN_INDEX_TWO) - .substring(2 + (64 - 2)), - web3.eth.abi - .encodeParameter("uint256", solanaTokenTwoContribution) - .substring(2), + web3.eth.abi.encodeParameter("uint16", SOLANA_CHAIN_ID).substring(2 + (64 - 4)), + web3.eth.abi.encodeParameter("uint8", acceptedTokensLengthSolana).substring(2 + (64 - 2)), + web3.eth.abi.encodeParameter("uint8", SOLANA_TOKEN_INDEX_ONE).substring(2 + (64 - 2)), + web3.eth.abi.encodeParameter("uint256", solanaTokenContribution).substring(2), + web3.eth.abi.encodeParameter("uint8", SOLANA_TOKEN_INDEX_TWO).substring(2 + (64 - 2)), + web3.eth.abi.encodeParameter("uint256", solanaTokenTwoContribution).substring(2), ]; const vm = await signAndEncodeVM( @@ -4983,22 +3935,12 @@ contract("ICCO", function(accounts) { // construct contributions payload coming from ethereum contributor const ethereumContributionsSealed = [ - web3.eth.abi - .encodeParameter("uint8", payloadIdType2) - .substring(2 + (64 - 2)), + web3.eth.abi.encodeParameter("uint8", payloadIdType2).substring(2 + (64 - 2)), web3.eth.abi.encodeParameter("uint256", SALE_5_ID).substring(2), - web3.eth.abi - .encodeParameter("uint16", TEST_CHAIN_ID) - .substring(2 + (64 - 4)), - web3.eth.abi - .encodeParameter("uint8", acceptedTokensLengthEthereum) - .substring(2 + (64 - 2)), - web3.eth.abi - .encodeParameter("uint8", ETH_TOKEN_INDEX) - .substring(2 + (64 - 2)), - web3.eth.abi - .encodeParameter("uint256", ethereumTokenContribution) - .substring(2), + web3.eth.abi.encodeParameter("uint16", TEST_CHAIN_ID).substring(2 + (64 - 4)), + web3.eth.abi.encodeParameter("uint8", acceptedTokensLengthEthereum).substring(2 + (64 - 2)), + web3.eth.abi.encodeParameter("uint8", ETH_TOKEN_INDEX).substring(2 + (64 - 2)), + web3.eth.abi.encodeParameter("uint256", ethereumTokenContribution).substring(2), ]; const vm2 = await signAndEncodeVM( @@ -5020,22 +3962,11 @@ contract("ICCO", function(accounts) { }); // verify contributions with conductor getter - const contributions = await initialized.methods - .saleContributions(SALE_5_ID) - .call(); + const contributions = await initialized.methods.saleContributions(SALE_5_ID).call(); - assert.equal( - solanaTokenContribution, - contributions[parseInt(SOLANA_TOKEN_INDEX_ONE)] - ); - assert.equal( - solanaTokenTwoContribution, - contributions[parseInt(SOLANA_TOKEN_INDEX_TWO)] - ); - assert.equal( - ethereumTokenContribution, - contributions[parseInt(ETH_TOKEN_INDEX)] - ); + assert.equal(solanaTokenContribution, contributions[parseInt(SOLANA_TOKEN_INDEX_ONE)]); + assert.equal(solanaTokenTwoContribution, contributions[parseInt(SOLANA_TOKEN_INDEX_TWO)]); + assert.equal(ethereumTokenContribution, contributions[parseInt(ETH_TOKEN_INDEX)]); }); it("conductor sealSale should emit Solana specific VAA when accepting Solana tokens", async function() { @@ -5048,10 +3979,7 @@ contract("ICCO", function(accounts) { const ethereumTokenAllocation = "5000000000000"; const excessContribution = "0"; // same for all tokens - no excess contributions - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); // seal the sale await initialized.methods.sealSale(SALE_5_ID).send({ @@ -5072,33 +4000,18 @@ contract("ICCO", function(accounts) { // parse the solana and ethereum saleSealed payloads together // payload id let index = 2; - assert.equal( - ethereumSealedPayload.payload.substr(index, 2), - payloadIdType3 - ); + assert.equal(ethereumSealedPayload.payload.substr(index, 2), payloadIdType3); assert.equal(solanaSealedPayload.payload.substr(index, 2), payloadIdType3); index += 2; // sale id - assert.equal( - parseInt(ethereumSealedPayload.payload.substr(index, 64), 16), - SALE_5_ID - ); - assert.equal( - parseInt(solanaSealedPayload.payload.substr(index, 64), 16), - SALE_5_ID - ); + assert.equal(parseInt(ethereumSealedPayload.payload.substr(index, 64), 16), SALE_5_ID); + assert.equal(parseInt(solanaSealedPayload.payload.substr(index, 64), 16), SALE_5_ID); index += 64; // allocations length - assert.equal( - ethereumSealedPayload.payload.substr(index, 2), - numTokensInEthereumPayload - ); - assert.equal( - solanaSealedPayload.payload.substr(index, 2), - numTokensInSolanaPayload - ); + assert.equal(ethereumSealedPayload.payload.substr(index, 2), numTokensInEthereumPayload); + assert.equal(solanaSealedPayload.payload.substr(index, 2), numTokensInSolanaPayload); index += 2; // copy index @@ -5106,108 +4019,63 @@ contract("ICCO", function(accounts) { let ethereumIndex = index; // parse solana token allocations and excess contributions - assert.equal( - solanaSealedPayload.payload.substr(solanaIndex, 2), - SOLANA_TOKEN_INDEX_ONE - ); + assert.equal(solanaSealedPayload.payload.substr(solanaIndex, 2), SOLANA_TOKEN_INDEX_ONE); solanaIndex += 2; // solana allocation - assert.equal( - parseInt(solanaSealedPayload.payload.substr(solanaIndex, 64), 16), - solanaTokenAllocation - ); + assert.equal(parseInt(solanaSealedPayload.payload.substr(solanaIndex, 64), 16), solanaTokenAllocation); solanaIndex += 64; // solana excess contribution - assert.equal( - parseInt(solanaSealedPayload.payload.substr(solanaIndex, 64), 16), - excessContribution - ); + assert.equal(parseInt(solanaSealedPayload.payload.substr(solanaIndex, 64), 16), excessContribution); solanaIndex += 64; // second allocation for solana tokens - assert.equal( - solanaSealedPayload.payload.substr(solanaIndex, 2), - SOLANA_TOKEN_INDEX_TWO - ); + assert.equal(solanaSealedPayload.payload.substr(solanaIndex, 2), SOLANA_TOKEN_INDEX_TWO); solanaIndex += 2; // solana allocation - assert.equal( - parseInt(solanaSealedPayload.payload.substr(solanaIndex, 64), 16), - solanaTokenTwoAllocation - ); + assert.equal(parseInt(solanaSealedPayload.payload.substr(solanaIndex, 64), 16), solanaTokenTwoAllocation); solanaIndex += 64; // solana excess contribution - assert.equal( - parseInt(solanaSealedPayload.payload.substr(solanaIndex, 64), 16), - excessContribution - ); + assert.equal(parseInt(solanaSealedPayload.payload.substr(solanaIndex, 64), 16), excessContribution); solanaIndex += 64; // ethereum saleSealed wormhole message - assert.equal( - ethereumSealedPayload.payload.substr(ethereumIndex, 2), - ETH_TOKEN_INDEX - ); + assert.equal(ethereumSealedPayload.payload.substr(ethereumIndex, 2), ETH_TOKEN_INDEX); ethereumIndex += 2; // eth allocation - assert.equal( - parseInt(ethereumSealedPayload.payload.substr(ethereumIndex, 64), 16), - ethereumTokenAllocation - ); + assert.equal(parseInt(ethereumSealedPayload.payload.substr(ethereumIndex, 64), 16), ethereumTokenAllocation); ethereumIndex += 64; // eth excessContribution - assert.equal( - parseInt(ethereumSealedPayload.payload.substr(ethereumIndex, 64), 16), - excessContribution - ); + assert.equal(parseInt(ethereumSealedPayload.payload.substr(ethereumIndex, 64), 16), excessContribution); ethereumIndex += 64; // index of solana token one in ethereum message - assert.equal( - ethereumSealedPayload.payload.substr(ethereumIndex, 2), - SOLANA_TOKEN_INDEX_ONE - ); + assert.equal(ethereumSealedPayload.payload.substr(ethereumIndex, 2), SOLANA_TOKEN_INDEX_ONE); ethereumIndex += 2; // allocation of solana token one in ethereum message - assert.equal( - parseInt(ethereumSealedPayload.payload.substr(ethereumIndex, 64), 16), - solanaTokenAllocation - ); + assert.equal(parseInt(ethereumSealedPayload.payload.substr(ethereumIndex, 64), 16), solanaTokenAllocation); ethereumIndex += 64; // solana excess contribution for token one - assert.equal( - parseInt(ethereumSealedPayload.payload.substr(ethereumIndex, 64), 16), - excessContribution - ); + assert.equal(parseInt(ethereumSealedPayload.payload.substr(ethereumIndex, 64), 16), excessContribution); ethereumIndex += 64; // index of solana token two in ethereum message - assert.equal( - ethereumSealedPayload.payload.substr(ethereumIndex, 2), - SOLANA_TOKEN_INDEX_TWO - ); + assert.equal(ethereumSealedPayload.payload.substr(ethereumIndex, 2), SOLANA_TOKEN_INDEX_TWO); ethereumIndex += 2; // allocation of solana token one in ethereum message - assert.equal( - parseInt(ethereumSealedPayload.payload.substr(ethereumIndex, 64), 16), - solanaTokenTwoAllocation - ); + assert.equal(parseInt(ethereumSealedPayload.payload.substr(ethereumIndex, 64), 16), solanaTokenTwoAllocation); ethereumIndex += 64; // solana excess contribution for token two - assert.equal( - parseInt(ethereumSealedPayload.payload.substr(ethereumIndex, 64), 16), - excessContribution - ); + assert.equal(parseInt(ethereumSealedPayload.payload.substr(ethereumIndex, 64), 16), excessContribution); ethereumIndex += 64; }); @@ -5240,10 +4108,7 @@ contract("ICCO", function(accounts) { await SOLD_TOKEN.mint(SELLER, saleTokenAmount); await SOLD_TOKEN.approve(TokenSaleConductor.address, saleTokenAmount); - const initializedConductor = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initializedConductor = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); const initializedContributor = new web3.eth.Contract( ContributorImplementationFullABI, TokenSaleContributor.address @@ -5268,26 +4133,16 @@ contract("ICCO", function(accounts) { // create accepted tokens array const acceptedTokens = [ - [ - TEST_CHAIN_ID, - "0x000000000000000000000000" + CONTRIBUTED_TOKEN_ONE.address.substr(2), - tokenOneConversionRate, - ], - [ - TEST_CHAIN_ID, - "0x000000000000000000000000" + CONTRIBUTED_TOKEN_TWO.address.substr(2), - tokenTwoConversionRate, - ], + [TEST_CHAIN_ID, "0x000000000000000000000000" + CONTRIBUTED_TOKEN_ONE.address.substr(2), tokenOneConversionRate], + [TEST_CHAIN_ID, "0x000000000000000000000000" + CONTRIBUTED_TOKEN_TWO.address.substr(2), tokenTwoConversionRate], ]; // create the sale - await initializedConductor.methods - .createSale(saleParams, acceptedTokens) - .send({ - value: WORMHOLE_FEE * 1, - from: SELLER, - gasLimit: GAS_LIMIT, - }); + await initializedConductor.methods.createSale(saleParams, acceptedTokens).send({ + value: WORMHOLE_FEE * 1, + from: SELLER, + gasLimit: GAS_LIMIT, + }); SALE_6_ID = SALE_5_ID + 1; @@ -5317,9 +4172,7 @@ contract("ICCO", function(accounts) { }); // verify getSaleTimeFrame getter - const saleTimeframe = await initializedContributor.methods - .getSaleTimeframe(SALE_6_ID) - .call(); + const saleTimeframe = await initializedContributor.methods.getSaleTimeframe(SALE_6_ID).call(); assert.equal(saleTimeframe.start, SALE_6_START); assert.equal(saleTimeframe.end, SALE_6_END); @@ -5333,26 +4186,15 @@ contract("ICCO", function(accounts) { const tokenOneContributionAmount = "6000"; const tokenTwoContributionAmount = "1000"; - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); // approve contribution amounts - await CONTRIBUTED_TOKEN_ONE.approve( - TokenSaleContributor.address, - tokenOneContributionAmount, - { - from: BUYER_ONE, - } - ); - await CONTRIBUTED_TOKEN_TWO.approve( - TokenSaleContributor.address, - tokenTwoContributionAmount, - { - from: BUYER_TWO, - } - ); + await CONTRIBUTED_TOKEN_ONE.approve(TokenSaleContributor.address, tokenOneContributionAmount, { + from: BUYER_ONE, + }); + await CONTRIBUTED_TOKEN_TWO.approve(TokenSaleContributor.address, tokenTwoContributionAmount, { + from: BUYER_TWO, + }); // perform "kyc" and contribute to the token sale for BUYER_ONE const kycSig1 = await signContribution( @@ -5363,17 +4205,10 @@ contract("ICCO", function(accounts) { BUYER_ONE, kycSignerPK ); - await initialized.methods - .contribute( - SALE_6_ID, - TOKEN_ONE_INDEX, - tokenOneContributionAmount, - kycSig1 - ) - .send({ - from: BUYER_ONE, - gasLimit: GAS_LIMIT, - }); + await initialized.methods.contribute(SALE_6_ID, TOKEN_ONE_INDEX, tokenOneContributionAmount, kycSig1).send({ + from: BUYER_ONE, + gasLimit: GAS_LIMIT, + }); const kycSig2 = await signContribution( CONDUCTOR_BYTES32_ADDRESS, @@ -5383,17 +4218,10 @@ contract("ICCO", function(accounts) { BUYER_TWO, kycSignerPK ); - await initialized.methods - .contribute( - SALE_6_ID, - TOKEN_TWO_INDEX, - tokenTwoContributionAmount, - kycSig2 - ) - .send({ - from: BUYER_TWO, - gasLimit: GAS_LIMIT, - }); + await initialized.methods.contribute(SALE_6_ID, TOKEN_TWO_INDEX, tokenTwoContributionAmount, kycSig2).send({ + from: BUYER_TWO, + gasLimit: GAS_LIMIT, + }); }); it("conductor and contributor should attest contributions and seal the sixth sale correctly", async function() { @@ -5407,25 +4235,16 @@ contract("ICCO", function(accounts) { const tokenOneContributionAmount = "6000"; const tokenTwoContributionAmount = "1000"; - const initializedConductor = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initializedConductor = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); const initializedContributor = new web3.eth.Contract( ContributorImplementationFullABI, TokenSaleContributor.address ); // fetch the sale token balance of the refund recipient before sealing the sale - const refundRecipientSaleTokenBalanceBefore = await SOLD_TOKEN.balanceOf( - SALE_6_REFUND_RECIPIENT - ); - const recipientTokenOneBalanceBefore = await CONTRIBUTED_TOKEN_ONE.balanceOf( - SELLER - ); - const recipientTokenTwoBalanceBefore = await CONTRIBUTED_TOKEN_TWO.balanceOf( - SELLER - ); + const refundRecipientSaleTokenBalanceBefore = await SOLD_TOKEN.balanceOf(SALE_6_REFUND_RECIPIENT); + const recipientTokenOneBalanceBefore = await CONTRIBUTED_TOKEN_ONE.balanceOf(SELLER); + const recipientTokenTwoBalanceBefore = await CONTRIBUTED_TOKEN_TWO.balanceOf(SELLER); // attest contributions await initializedContributor.methods.attestContributions(SALE_6_ID).send({ @@ -5495,13 +4314,10 @@ contract("ICCO", function(accounts) { // verify that the saleRecipient received the sale token refund // fetch the sale token balance of the refund recipient after sealing the sale - const refundRecipientSaleTokenBalanceAfter = await SOLD_TOKEN.balanceOf( - SALE_6_REFUND_RECIPIENT - ); + const refundRecipientSaleTokenBalanceAfter = await SOLD_TOKEN.balanceOf(SALE_6_REFUND_RECIPIENT); assert.equal( - parseInt(refundRecipientSaleTokenBalanceAfter) - - parseInt(refundRecipientSaleTokenBalanceBefore), + parseInt(refundRecipientSaleTokenBalanceAfter) - parseInt(refundRecipientSaleTokenBalanceBefore), expectedSaleTokenRefund ); @@ -5526,39 +4342,28 @@ contract("ICCO", function(accounts) { assert.equal(tokenTwoExcessContribution, expectedExcessContributions); // confirm that the sale recipient received the contributed tokens - const recipientTokenOneBalanceAfter = await CONTRIBUTED_TOKEN_ONE.balanceOf( - SELLER - ); - const recipientTokenTwoBalanceAfter = await CONTRIBUTED_TOKEN_TWO.balanceOf( - SELLER - ); + const recipientTokenOneBalanceAfter = await CONTRIBUTED_TOKEN_ONE.balanceOf(SELLER); + const recipientTokenTwoBalanceAfter = await CONTRIBUTED_TOKEN_TWO.balanceOf(SELLER); assert.equal( - parseInt(recipientTokenOneBalanceAfter) - - parseInt(recipientTokenOneBalanceBefore), + parseInt(recipientTokenOneBalanceAfter) - parseInt(recipientTokenOneBalanceBefore), tokenOneContributionAmount ); assert.equal( - parseInt(recipientTokenTwoBalanceAfter) - - parseInt(recipientTokenTwoBalanceBefore), + parseInt(recipientTokenTwoBalanceAfter) - parseInt(recipientTokenTwoBalanceBefore), tokenTwoContributionAmount ); }); it("contributor should not distribute tokens before the unlock time", async function() { - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); let failed = false; try { - await initialized.methods - .claimAllocation(SALE_6_ID, TOKEN_TWO_INDEX) - .send({ - from: BUYER_TWO, - gasLimit: GAS_LIMIT, - }); + await initialized.methods.claimAllocation(SALE_6_ID, TOKEN_TWO_INDEX).send({ + from: BUYER_TWO, + gasLimit: GAS_LIMIT, + }); } catch (e) { assert.equal( e.message, @@ -5578,10 +4383,7 @@ contract("ICCO", function(accounts) { const expectedBuyerOneAllocation = "6000"; // 75% of what is allocated const expectedBuyerTwoAllocation = "2000"; // 25% of what is allocated - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); // check balances before claiming tokens const buyerOneBalanceBefore = await SOLD_TOKEN.balanceOf(BUYER_ONE); @@ -5601,20 +4403,12 @@ contract("ICCO", function(accounts) { const buyerOneBalanceAfter = await SOLD_TOKEN.balanceOf(BUYER_ONE); const buyerTwoBalanceAfter = await SOLD_TOKEN.balanceOf(BUYER_TWO); - assert.equal( - parseInt(buyerOneBalanceAfter) - parseInt(buyerOneBalanceBefore), - expectedBuyerOneAllocation - ); - assert.equal( - parseInt(buyerTwoBalanceAfter) - parseInt(buyerTwoBalanceBefore), - expectedBuyerTwoAllocation - ); + assert.equal(parseInt(buyerOneBalanceAfter) - parseInt(buyerOneBalanceBefore), expectedBuyerOneAllocation); + assert.equal(parseInt(buyerTwoBalanceAfter) - parseInt(buyerTwoBalanceBefore), expectedBuyerTwoAllocation); }); it("conductor should not allow a sale to abort after the sale start time", async function() { - console.log( - "\n -------------------------- Other Tests --------------------------" - ); + console.log("\n -------------------------- Other Tests --------------------------"); // test variables const current_block = await web3.eth.getBlock("latest"); const saleStart = current_block.timestamp + 5; @@ -5628,10 +4422,7 @@ contract("ICCO", function(accounts) { const refundRecipient = accounts[0]; const isFixedPriceSale = false; - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); const saleId = await initialized.methods.getNextSaleId().call(); @@ -5656,16 +4447,8 @@ contract("ICCO", function(accounts) { // create accepted tokens array const acceptedTokens = [ - [ - TEST_CHAIN_ID, - "0x000000000000000000000000" + CONTRIBUTED_TOKEN_ONE.address.substr(2), - tokenOneConversionRate, - ], - [ - TEST_CHAIN_ID, - "0x000000000000000000000000" + CONTRIBUTED_TOKEN_TWO.address.substr(2), - tokenTwoConversionRate, - ], + [TEST_CHAIN_ID, "0x000000000000000000000000" + CONTRIBUTED_TOKEN_ONE.address.substr(2), tokenOneConversionRate], + [TEST_CHAIN_ID, "0x000000000000000000000000" + CONTRIBUTED_TOKEN_TWO.address.substr(2), tokenTwoConversionRate], ]; // create another sale @@ -5715,10 +4498,7 @@ contract("ICCO", function(accounts) { const nativeContractAddress = "0x00"; // set to 0 for the test const isFixedPriceSale = false; - const initializedConductor = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initializedConductor = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); const initializedContributor = new web3.eth.Contract( ContributorImplementationFullABI, TokenSaleContributor.address @@ -5741,8 +4521,7 @@ contract("ICCO", function(accounts) { ); await soldToken.mint(SELLER, saleTokenMintAmount); await soldToken.approve(TokenSaleConductor.address, saleTokenAmount); - const soldTokenBytes32 = - "0x000000000000000000000000" + soldToken.address.substr(2); + const soldTokenBytes32 = "0x000000000000000000000000" + soldToken.address.substr(2); // create array (solidity struct) for sale params const saleParams = [ @@ -5763,11 +4542,7 @@ contract("ICCO", function(accounts) { // create accepted tokens array with a bad token address (non-ERC20) const acceptedTokens = [ - [ - TEST_CHAIN_ID, - "0x000000000000000000000000" + CONTRIBUTED_TOKEN_ONE.address.substr(2), - tokenOneConversionRate, - ], + [TEST_CHAIN_ID, "0x000000000000000000000000" + CONTRIBUTED_TOKEN_ONE.address.substr(2), tokenOneConversionRate], [ TEST_CHAIN_ID, "0x000000000000000000000000" + accounts[0].substr(2), // create bad address by using wallet address @@ -5776,13 +4551,11 @@ contract("ICCO", function(accounts) { ]; // create another sale - await initializedConductor.methods - .createSale(saleParams, acceptedTokens) - .send({ - value: WORMHOLE_FEE, - from: SELLER, - gasLimit: GAS_LIMIT, - }); + await initializedConductor.methods.createSale(saleParams, acceptedTokens).send({ + value: WORMHOLE_FEE, + from: SELLER, + gasLimit: GAS_LIMIT, + }); // grab the message generated by the conductor const log = ( @@ -5812,10 +4585,7 @@ contract("ICCO", function(accounts) { gasLimit: GAS_LIMIT, }); } catch (e) { - assert.equal( - e.message, - "Returned error: VM Exception while processing transaction: revert non-existent ERC20" - ); + assert.equal(e.message, "Returned error: VM Exception while processing transaction: revert non-existent ERC20"); failed = true; } @@ -5841,18 +4611,14 @@ contract("ICCO", function(accounts) { const nativeContractAddress = "0x00"; // set to 0 for the test const isFixedPriceSale = false; - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); // create sale token again const saleTokenMintAmount = "2000"; const soldToken = await TokenImplementation.new(); const soldTokenName = "Sold Token"; const soldTokenSymbol = "SOLD"; - const soldTokenBytes32 = - "0x000000000000000000000000" + soldToken.address.substr(2); + const soldTokenBytes32 = "0x000000000000000000000000" + soldToken.address.substr(2); await soldToken.initialize( soldTokenName, @@ -5885,11 +4651,7 @@ contract("ICCO", function(accounts) { // create accepted tokens array const acceptedTokens = [ - [ - TEST_CHAIN_ID, - "0x000000000000000000000000" + CONTRIBUTED_TOKEN_ONE.address.substr(2), - tokenOneConversionRate, - ], + [TEST_CHAIN_ID, "0x000000000000000000000000" + CONTRIBUTED_TOKEN_ONE.address.substr(2), tokenOneConversionRate], [ TEST_CHAIN_ID, "0x000000000000000000000000" + CONTRIBUTED_TOKEN_TWO.address.substr(2), // create bad address @@ -5933,18 +4695,14 @@ contract("ICCO", function(accounts) { const nativeContractAddress = "0x00"; // set to 0 for the test const isFixedPriceSale = false; - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); // create sale token again const saleTokenMintAmount = "2000"; const soldToken = await TokenImplementation.new(); const soldTokenName = "Sold Token"; const soldTokenSymbol = "SOLD"; - const soldTokenBytes32 = - "0x000000000000000000000000" + soldToken.address.substr(2); + const soldTokenBytes32 = "0x000000000000000000000000" + soldToken.address.substr(2); await soldToken.initialize( soldTokenName, @@ -5977,11 +4735,7 @@ contract("ICCO", function(accounts) { // create accepted tokens array const acceptedTokens = [ - [ - TEST_CHAIN_ID, - "0x000000000000000000000000" + CONTRIBUTED_TOKEN_ONE.address.substr(2), - tokenOneConversionRate, - ], + [TEST_CHAIN_ID, "0x000000000000000000000000" + CONTRIBUTED_TOKEN_ONE.address.substr(2), tokenOneConversionRate], ]; let failed = false; @@ -6030,8 +4784,7 @@ contract("ICCO", function(accounts) { const soldToken = await TokenImplementation.new(); const soldTokenName = "Sold Token"; const soldTokenSymbol = "SOLD"; - const soldTokenBytes32 = - "0x000000000000000000000000" + soldToken.address.substr(2); + const soldTokenBytes32 = "0x000000000000000000000000" + soldToken.address.substr(2); await soldToken.initialize( soldTokenName, @@ -6046,10 +4799,7 @@ contract("ICCO", function(accounts) { await soldToken.approve(TokenSaleConductor.address, saleTokenAmount); // setup smart contracts - const initializedConductor = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initializedConductor = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); const initializedContributor = new web3.eth.Contract( ContributorImplementationFullABI, TokenSaleContributor.address @@ -6078,21 +4828,15 @@ contract("ICCO", function(accounts) { // create accepted tokens array const acceptedTokens = [ - [ - TEST_CHAIN_ID, - "0x000000000000000000000000" + CONTRIBUTED_TOKEN_ONE.address.substr(2), - tokenOneConversionRate, - ], + [TEST_CHAIN_ID, "0x000000000000000000000000" + CONTRIBUTED_TOKEN_ONE.address.substr(2), tokenOneConversionRate], ]; // create another sale - await initializedConductor.methods - .createSale(saleParams, acceptedTokens) - .send({ - value: WORMHOLE_FEE, - from: SELLER, - gasLimit: GAS_LIMIT, - }); + await initializedConductor.methods.createSale(saleParams, acceptedTokens).send({ + value: WORMHOLE_FEE, + from: SELLER, + gasLimit: GAS_LIMIT, + }); // grab the message generated by the conductor const log = ( @@ -6124,13 +4868,9 @@ contract("ICCO", function(accounts) { await wait(5); // make contribution equal to the minRaise amount - await CONTRIBUTED_TOKEN_ONE.approve( - TokenSaleContributor.address, - maximumTokenRaise, - { - from: BUYER_ONE, - } - ); + await CONTRIBUTED_TOKEN_ONE.approve(TokenSaleContributor.address, maximumTokenRaise, { + from: BUYER_ONE, + }); // mint some more tokens to contribute with await CONTRIBUTED_TOKEN_ONE.mint(BUYER_ONE, maximumTokenRaise); @@ -6221,9 +4961,7 @@ contract("ICCO", function(accounts) { }); // confirm that the allocations and excessContributions are correct - const actualAllocation = await initializedContributor.methods - .getSaleAllocation(saleId, TOKEN_ONE_INDEX) - .call(); + const actualAllocation = await initializedContributor.methods.getSaleAllocation(saleId, TOKEN_ONE_INDEX).call(); const actualExcessContribution = await initializedContributor.methods .getSaleExcessContribution(saleId, TOKEN_ONE_INDEX) .call(); @@ -6273,27 +5011,15 @@ contract("ICCO", function(accounts) { ); // make sure the function is producing the expected result - assert.equal( - normalizedConversionRate1.toString(), - expectedNormalizedConversionRate1 - ); - assert.equal( - normalizedConversionRate2.toString(), - expectedNormalizedConversionRate2 - ); - assert.equal( - normalizedConversionRate3.toString(), - expectedNormalizedConversionRate3 - ); + assert.equal(normalizedConversionRate1.toString(), expectedNormalizedConversionRate1); + assert.equal(normalizedConversionRate2.toString(), expectedNormalizedConversionRate2); + assert.equal(normalizedConversionRate3.toString(), expectedNormalizedConversionRate3); }); }); contract("ICCO Library Upgrade", function(accounts) { it("conductor should accept a valid upgrade with library changes", async function() { - const initialized = new web3.eth.Contract( - ConductorImplementationFullABI, - TokenSaleConductor.address - ); + const initialized = new web3.eth.Contract(ConductorImplementationFullABI, TokenSaleConductor.address); // deploy mock contracts and link ICCOStructs library const structs = await MockICCOStructs.new(); @@ -6306,10 +5032,7 @@ contract("ICCO Library Upgrade", function(accounts) { "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc" ); - assert.equal( - before.toLowerCase(), - ConductorImplementation.address.toLowerCase() - ); + assert.equal(before.toLowerCase(), ConductorImplementation.address.toLowerCase()); await initialized.methods.upgrade(TEST_CHAIN_ID, mock.address).send({ value: 0, @@ -6325,37 +5048,24 @@ contract("ICCO Library Upgrade", function(accounts) { assert.equal(after.toLowerCase(), mock.address.toLowerCase()); // call new conductor methods to confirm the upgrade was successful - const mockImpl = new web3.eth.Contract( - MockConductorImplementation2.abi, - TokenSaleConductor.address - ); + const mockImpl = new web3.eth.Contract(MockConductorImplementation2.abi, TokenSaleConductor.address); - let isUpgraded = await mockImpl.methods - .testNewImplementationActive() - .call(); + let isUpgraded = await mockImpl.methods.testNewImplementationActive().call(); let isConductorUpgraded = await mockImpl.methods.upgradeSuccessful().call(); assert.ok(isUpgraded); assert.ok(isConductorUpgraded); // call new method in mock ICCO structs to confirm library upgrade was successful - const mockICCOLib = new web3.eth.Contract( - MockICCOStructs.abi, - structs.address - ); + const mockICCOLib = new web3.eth.Contract(MockICCOStructs.abi, structs.address); - let isLibraryUpgraded = await mockICCOLib.methods - .testNewLibraryActive() - .call(); + let isLibraryUpgraded = await mockICCOLib.methods.testNewLibraryActive().call(); assert.ok(isLibraryUpgraded); }); it("contributor should accept a valid upgrade with library changes", async function() { - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); // deploy mock contracts and link ICCOStructs library const structs = await MockICCOStructs.new(); @@ -6368,10 +5078,7 @@ contract("ICCO Library Upgrade", function(accounts) { "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc" ); - assert.equal( - before.toLowerCase(), - ContributorImplementation.address.toLowerCase() - ); + assert.equal(before.toLowerCase(), ContributorImplementation.address.toLowerCase()); await initialized.methods.upgrade(TEST_CHAIN_ID, mock.address).send({ value: 0, @@ -6387,30 +5094,18 @@ contract("ICCO Library Upgrade", function(accounts) { assert.equal(after.toLowerCase(), mock.address.toLowerCase()); // // call new contributor methods to confirm the upgrade was successful - const mockImpl = new web3.eth.Contract( - MockContributorImplementation2.abi, - TokenSaleContributor.address - ); + const mockImpl = new web3.eth.Contract(MockContributorImplementation2.abi, TokenSaleContributor.address); - let isUpgraded = await mockImpl.methods - .testNewImplementationActive() - .call(); - let isContributorUpgraded = await mockImpl.methods - .upgradeSuccessful() - .call(); + let isUpgraded = await mockImpl.methods.testNewImplementationActive().call(); + let isContributorUpgraded = await mockImpl.methods.upgradeSuccessful().call(); assert.ok(isUpgraded); assert.ok(isContributorUpgraded); // call new method in ICCO structs to confirm library upgrade was successful - const mockICCOLib = new web3.eth.Contract( - MockICCOStructs.abi, - structs.address - ); + const mockICCOLib = new web3.eth.Contract(MockICCOStructs.abi, structs.address); - let isLibraryUpgraded = await mockICCOLib.methods - .testNewLibraryActive() - .call(); + let isLibraryUpgraded = await mockICCOLib.methods.testNewLibraryActive().call(); assert.ok(isLibraryUpgraded); }); @@ -6424,40 +5119,21 @@ async function normalizeConversionRate( ) { const precision = 18; const normDecimals = denominationDecimals + precision - acceptedTokenDecimals; - let normalizedConversionRate = ethers.utils.parseUnits( - rawConversionRate, - normDecimals - ); + let normalizedConversionRate = ethers.utils.parseUnits(rawConversionRate, normDecimals); if (acceptedTokenDecimals === conductorDecimals) { return normalizedConversionRate; } else if (acceptedTokenDecimals > conductorDecimals) { - return normalizedConversionRate.div( - ethers.utils.parseUnits("1", acceptedTokenDecimals - conductorDecimals) - ); + return normalizedConversionRate.div(ethers.utils.parseUnits("1", acceptedTokenDecimals - conductorDecimals)); } else { - return normalizedConversionRate.mul( - ethers.utils.parseUnits("1", conductorDecimals - acceptedTokenDecimals) - ); + return normalizedConversionRate.mul(ethers.utils.parseUnits("1", conductorDecimals - acceptedTokenDecimals)); } } -const signContribution = async function( - conductorAddress, - saleId, - tokenIndex, - amount, - buyerAddress, - signer -) { +const signContribution = async function(conductorAddress, saleId, tokenIndex, amount, buyerAddress, signer) { // query for total contributed amount by this contributor - const initialized = new web3.eth.Contract( - ContributorImplementationFullABI, - TokenSaleContributor.address - ); - const totalContribution = await initialized.methods - .getSaleContribution(saleId, tokenIndex, buyerAddress) - .call(); + const initialized = new web3.eth.Contract(ContributorImplementationFullABI, TokenSaleContributor.address); + const totalContribution = await initialized.methods.getSaleContribution(saleId, tokenIndex, buyerAddress).call(); const body = [ web3.eth.abi.encodeParameter("bytes32", conductorAddress).substring(2), @@ -6478,9 +5154,7 @@ const signContribution = async function( const packSig = [ zeroPadBytes(signature.r.toString(16), 32), zeroPadBytes(signature.s.toString(16), 32), - web3.eth.abi - .encodeParameter("uint8", signature.recoveryParam) - .substr(2 + (64 - 2)), + web3.eth.abi.encodeParameter("uint8", signature.recoveryParam).substr(2 + (64 - 2)), ]; return "0x" + packSig.join(""); @@ -6500,20 +5174,14 @@ const signAndEncodeVM = async function( const body = [ web3.eth.abi.encodeParameter("uint32", timestamp).substring(2 + (64 - 8)), web3.eth.abi.encodeParameter("uint32", nonce).substring(2 + (64 - 8)), - web3.eth.abi - .encodeParameter("uint16", emitterChainId) - .substring(2 + (64 - 4)), + web3.eth.abi.encodeParameter("uint16", emitterChainId).substring(2 + (64 - 4)), web3.eth.abi.encodeParameter("bytes32", emitterAddress).substring(2), web3.eth.abi.encodeParameter("uint64", sequence).substring(2 + (64 - 16)), - web3.eth.abi - .encodeParameter("uint8", consistencyLevel) - .substring(2 + (64 - 2)), + web3.eth.abi.encodeParameter("uint8", consistencyLevel).substring(2 + (64 - 2)), data.substr(2), ]; - const hash = web3.utils.soliditySha3( - web3.utils.soliditySha3("0x" + body.join("")) - ); + const hash = web3.utils.soliditySha3(web3.utils.soliditySha3("0x" + body.join(""))); let signatures = ""; @@ -6526,9 +5194,7 @@ const signAndEncodeVM = async function( web3.eth.abi.encodeParameter("uint8", i).substring(2 + (64 - 2)), zeroPadBytes(signature.r.toString(16), 32), zeroPadBytes(signature.s.toString(16), 32), - web3.eth.abi - .encodeParameter("uint8", signature.recoveryParam) - .substr(2 + (64 - 2)), + web3.eth.abi.encodeParameter("uint8", signature.recoveryParam).substr(2 + (64 - 2)), ]; signatures += packSig.join(""); @@ -6536,12 +5202,8 @@ const signAndEncodeVM = async function( const vm = [ web3.eth.abi.encodeParameter("uint8", 1).substring(2 + (64 - 2)), - web3.eth.abi - .encodeParameter("uint32", guardianSetIndex) - .substring(2 + (64 - 8)), - web3.eth.abi - .encodeParameter("uint8", signers.length) - .substring(2 + (64 - 2)), + web3.eth.abi.encodeParameter("uint32", guardianSetIndex).substring(2 + (64 - 8)), + web3.eth.abi.encodeParameter("uint8", signers.length).substring(2 + (64 - 2)), signatures, body.join(""),