Skip to content

Commit

Permalink
fix test case
Browse files Browse the repository at this point in the history
  • Loading branch information
SatyamSB committed Apr 11, 2018
1 parent 9d84401 commit d913d00
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 30 deletions.
2 changes: 1 addition & 1 deletion test/helpers/contracts/TestSTOFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract TestSTOFactory is IModuleFactory {
}

function deploy(bytes _data) external returns(address) {
//polyToken.transferFrom(msg.sender, owner, getCost());
polyToken.transferFrom(msg.sender, owner, getCost());
//Check valid bytes - can only call module init function
DummySTO dummySTO = new DummySTO(msg.sender);
//Checks that _data is valid (not calling anything it shouldn't)
Expand Down
89 changes: 60 additions & 29 deletions test/security_token_registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ contract('SecurityTokenRegistry', accounts => {
let I_STVersion;
let I_SecurityToken;
let I_DummySTO;
let I_PolyToken;
let I_PolyFaucet;
let I_STVersion002;
let I_SecurityToken002;
Expand Down Expand Up @@ -113,12 +112,12 @@ contract('SecurityTokenRegistry', accounts => {

// ----------- POLYMATH NETWORK Configuration ------------

// Step 0: Deploy the Polytoken Contract
I_PolyToken = await PolyToken.new();
// Step 0: Deploy the token Faucet
I_PolyFaucet = await PolyTokenFaucet.new();

// STEP 1: Deploy the ModuleRegistry

I_ModuleRegistry = await ModuleRegistry.new({from:account_polymath});
I_ModuleRegistry = await ModuleRegistry.new({ from: account_polymath });

assert.notEqual(
I_ModuleRegistry.address.valueOf(),
Expand All @@ -128,7 +127,7 @@ contract('SecurityTokenRegistry', accounts => {

// STEP 2: Deploy the GeneralTransferManagerFactory

I_GeneralTransferManagerFactory = await GeneralTransferManagerFactory.new(I_PolyToken.address, {from:account_polymath});
I_GeneralTransferManagerFactory = await GeneralTransferManagerFactory.new(I_PolyFaucet.address, { from: account_polymath });

assert.notEqual(
I_GeneralTransferManagerFactory.address.valueOf(),
Expand All @@ -138,25 +137,16 @@ contract('SecurityTokenRegistry', accounts => {

// STEP 3: Deploy the GeneralDelegateManagerFactory

I_GeneralPermissionManagerFactory = await GeneralPermissionManagerFactory.new(I_PolyToken.address, {from:account_polymath});
I_GeneralPermissionManagerFactory = await GeneralPermissionManagerFactory.new(I_PolyFaucet.address, { from: account_polymath });

assert.notEqual(
I_GeneralPermissionManagerFactory.address.valueOf(),
"0x0000000000000000000000000000000000000000",
"GeneralDelegateManagerFactory contract was not deployed"
);

// STEP 4: Deploy the CappedSTOFactory

I_TestSTOFactory = await TestSTOFactory.new(I_PolyToken.address, { from: token_owner });

assert.notEqual(
I_TestSTOFactory.address.valueOf(),
"0x0000000000000000000000000000000000000000",
"TestSTOFactory contract was not deployed"
);

// STEP 5: Register the Modules with the ModuleRegistry contract
// STEP 4: Register the Modules with the ModuleRegistry contract

// (A) : Register the GeneralTransferManagerFactory
await I_ModuleRegistry.registerModule(I_GeneralTransferManagerFactory.address, { from: account_polymath });
Expand All @@ -166,10 +156,7 @@ contract('SecurityTokenRegistry', accounts => {
await I_ModuleRegistry.registerModule(I_GeneralPermissionManagerFactory.address, { from: account_polymath });
await I_ModuleRegistry.verifyModule(I_GeneralPermissionManagerFactory.address, true, { from: account_polymath });

// (C) : Register the STOFactory
await I_ModuleRegistry.registerModule(I_TestSTOFactory.address, { from: token_owner });

// Step 6: Deploy the TickerRegistry
// Step 5: Deploy the TickerRegistry

I_TickerRegistry = await TickerRegistry.new({ from: account_polymath });

Expand All @@ -179,7 +166,7 @@ contract('SecurityTokenRegistry', accounts => {
"TickerRegistry contract was not deployed",
);

// Step 7: Deploy the STversionProxy contract
// Step 6: Deploy the STversionProxy contract

I_STVersion = await STVersion.new(I_GeneralTransferManagerFactory.address, I_GeneralPermissionManagerFactory.address, {from : account_polymath });

Expand All @@ -189,8 +176,18 @@ contract('SecurityTokenRegistry', accounts => {
"STVersion contract was not deployed",
);

// Step 8: Deploy the token Faucet
I_PolyFaucet = await PolyTokenFaucet.new();
// STEP 8: Deploy the CappedSTOFactory

I_TestSTOFactory = await TestSTOFactory.new(I_PolyFaucet.address, { from: token_owner });

assert.notEqual(
I_TestSTOFactory.address.valueOf(),
"0x0000000000000000000000000000000000000000",
"TestSTOFactory contract was not deployed"
);

// (C) : Register the STOFactory
await I_ModuleRegistry.registerModule(I_TestSTOFactory.address, { from: token_owner });

// Step 9: Deploy the SecurityTokenRegistry

Expand Down Expand Up @@ -374,7 +371,7 @@ contract('SecurityTokenRegistry', accounts => {
);
});

it("Should successfully attach the STO factory with the security token", async () => {
it("Should failed in attaching the STO factory with the security token -- because securityToken doesn't have sufficient balance", async () => {
let bytesSTO = web3.eth.abi.encodeFunctionCall(
functionSignature,
[
Expand All @@ -384,26 +381,60 @@ contract('SecurityTokenRegistry', accounts => {
someString,
]);

let errorThrown = false;

try {
const tx = await I_SecurityToken.addModule(
I_TestSTOFactory.address,
bytesSTO,
(1000 * Math.pow(10, 18)),
(1000 * Math.pow(10, 18)),
true,
{
from: token_owner,
gas: 2500000
});
} catch(error) {
console.log(`Tx. get failed. Becuase securityToken doesn't have sufficient POLY to pay`);
errorThrown = true;
}
assert.ok(errorThrown, message);
});

it("Should successfully attach the STO factory with the security token", async () => {
let bytesSTO = web3.eth.abi.encodeFunctionCall(
functionSignature,
[
(latestTime() + duration.seconds(500)),
(latestTime() + duration.days(30)),
cap,
someString,
]);

await I_PolyFaucet.getTokens((1000 * Math.pow(10, 18)), I_SecurityToken.address);

const tx = await I_SecurityToken.addModule(
I_TestSTOFactory.address,
bytesSTO,
(1000 * Math.pow(10, 18)),
(1000 * Math.pow(10, 18)),
false,
true,
{
from: token_owner,
gas: 2500000
});

assert.equal(tx.logs[2].args._type, stoKey, "TestSTO doesn't get deployed");
assert.equal(tx.logs[3].args._type, stoKey, "TestSTO doesn't get deployed");
assert.equal(
web3.utils.toAscii(tx.logs[2].args._name)
web3.utils.toAscii(tx.logs[3].args._name)
.replace(/\u0000/g, ''),
"TestSTO",
"TestSTOFactory module was not added"
);
I_DummySTO = DummySTO.at(tx.logs[2].args._module);

I_DummySTO = DummySTO.at(tx.logs[3].args._module);
});

});


Expand Down

0 comments on commit d913d00

Please sign in to comment.