Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions lib/AbiBinProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ const fs = require('fs'),
path = require('path');
//__NOT_FOR_WEB__END__

const Mosaic = require('@openstfoundation/mosaic-tbd');
const AbiBinProvider = Mosaic.AbiBinProvider;
const { AbiBinProvider } = require('@openstfoundation/mosaic.js');

let DEFAULT_ABI_FOLDER_PATH, DEFAULT_BIN_FOLDER_PATH;
//__NOT_FOR_WEB__BEGIN__
Expand All @@ -22,18 +21,32 @@ class OpenSTAbiBinProvider extends AbiBinProvider {
/**
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why OpenSTAbiBinProvider is inheriting from AbiBinProvider of mosaic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenST is on top of mosaic. Inheriting AbiBinProvider of mosaic helps end users to retrieve abi/bin of mosaic with a single OpenST AbiBinProvider object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But should they need to? Why?

* Constructor for OpenSTAbiBinProvider.
*
* @param abiFolderPath Folder path where abi is present.
* @param binFolderPath Folder path where bin is present.
* @param mosaicAbiFolderPath Folder path where mosaic abi is present.
* @param mosaicBinFolderPath Folder path where mosaic bin is present.
* @param {string} [abiFolderPath] Folder path where abi is present.
* @param {string} [binFolderPath] Folder path where bin is present.
*/
constructor(abiFolderPath, binFolderPath, mosaicAbiFolderPath, mosaicBinFolderPath) {
abiFolderPath = abiFolderPath || DEFAULT_ABI_FOLDER_PATH;
binFolderPath = binFolderPath || DEFAULT_BIN_FOLDER_PATH;
super(abiFolderPath, binFolderPath);
constructor(abiFolderPath, binFolderPath) {
const abiDirectoryPath = abiFolderPath || DEFAULT_ABI_FOLDER_PATH;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DEFAULT_ABI_FOLDER_PATH and DEFAULT_BIN_FOLDER_PATH are guarded (NOT_FOR_WEB__BEGIN). Should we check that if they are undefined and abiFolderPath, binFolderPath are not passed and raise error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. However I am still not sure how can DEFAULT_ABI_FOLDER_PATH, DEFAULT_BIN_FOLDER_PATH can be undefined.

Having said that once openst-contracts npm package are integrated, we will not need path dependencies .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abhayks1 can you please expand on that? I cannot follow.

const binDirectoryPath = binFolderPath || DEFAULT_BIN_FOLDER_PATH;
super();

const oThis = this;
oThis.mosaicAbiBinProvider = new AbiBinProvider(mosaicAbiFolderPath, mosaicBinFolderPath);
oThis.mosaicAbiBinProvider = new AbiBinProvider();

// add all ABIs from abiDirectoryPath
fs.readdirSync(abiDirectoryPath).forEach((abiFile) => {
const fPath = path.resolve(abiDirectoryPath, abiFile);
const contractName = path.basename(abiFile, path.extname(abiFile));
const contractAbi = JSON.parse(fs.readFileSync(fPath));
oThis.addABI(contractName, contractAbi);
});

// add all bins from binDirectoryPath
fs.readdirSync(binDirectoryPath).forEach((binFile) => {
const fPath = path.resolve(binDirectoryPath, binFile);
const contractName = path.basename(binFile, path.extname(binFile));
const contractBin = fs.readFileSync(fPath, 'utf8');
oThis.addBIN(contractName, contractBin);
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/ContractInteract/Recovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Utils = require('../../utils/Utils');

const Contracts = require('../Contracts');

const Mosaic = require('@openstfoundation/mosaic-tbd');
const Mosaic = require('@openstfoundation/mosaic.js');

const TypedDataClass = Mosaic.Utils.EIP712TypedData;

Expand Down
3 changes: 1 addition & 2 deletions lib/Contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

const Web3 = require('web3');
const AbiBinProvider = require('./AbiBinProvider');
const Mosaic = require('@openstfoundation/mosaic-tbd');
const Contracts = Mosaic.Contracts;
const { Contracts } = require('@openstfoundation/mosaic.js');

const abiBinProvider = new AbiBinProvider();

Expand Down
2 changes: 1 addition & 1 deletion lib/helper/GnosisSafe.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const AbiBinProvider = require('./../AbiBinProvider');
const Mosaic = require('@openstfoundation/mosaic-tbd'),
const Mosaic = require('@openstfoundation/mosaic.js'),
TypedDataClass = Mosaic.Utils.EIP712TypedData;

const Utils = require('../../utils/Utils');
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"pre-commit": "lint-staged"
},
"dependencies": {
"@openstfoundation/mosaic-tbd": "https://github.com/OpenSTFoundation/mosaic-tbd.git"
"@openstfoundation/mosaic.js": "0.10.0-beta.2"
},
"devDependencies": {
"@babel/core": "7.1.0",
Expand Down Expand Up @@ -58,7 +58,9 @@
"wait-port": "0.2.2",
"assert": "^1.4.1",
"ethereumjs-util": "^6.1.0",
"sinon": "7.2.3"
"sinon": "7.2.3",
"web3": "1.0.0-beta.37",
"web3-eth-accounts": "1.0.0-beta.37"
},
"pre-commit": {
"run": [
Expand Down
18 changes: 10 additions & 8 deletions test/integration/DelayedRecovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ const Web3 = require('web3');

const { dockerSetup, dockerTeardown } = require('./../../utils/docker');

const Mosaic = require('@openstfoundation/mosaic-tbd');
const config = require('../utils/configReader');

const Mosaic = require('@openstfoundation/mosaic.js');
const ConfigReader = require('../utils/configReader');
const UserSetup = require('../../lib/setup/User.js');
const User = require('../../lib/helper/User.js');
const MockContractsDeployer = require('../utils/MockContractsDeployer.js');
const TokenRulesSetup = require('../../lib/setup/TokenRules.js');
const AbiBinProvider = require('../../lib/AbiBinProvider.js');

const { OrganizationHelper } = Mosaic.ChainSetup;

const abiBinProvider = new AbiBinProvider();

const GNOSIS_SAFE_CONTRACT_NAME = 'GnosisSafe';
Expand Down Expand Up @@ -313,15 +313,17 @@ describe('Delayed Recovery', async () => {
const mockToken = mockTokenDeployerInstance.addresses.MockToken;

const organizationOwnerAddress = deployerAddress;
const orgHelper = new OrganizationHelper(auxiliaryWeb3, null);
const { Organization } = Mosaic.ContractInteract;
const orgConfig = {
deployer: deployerAddress,
owner: organizationOwnerAddress,
workers: organizationWorkerAddress,
workerExpirationHeight: '20000000'
admin: organizationWorkerAddress,
workers: [organizationWorkerAddress],
workerExpirationHeight: config.workerExpirationHeight
};
await orgHelper.setup(orgConfig);
const organizationAddress = orgHelper.address;
const organizationContractInstance = await Organization.setup(auxiliaryWeb3, orgConfig);
const organizationAddress = organizationContractInstance.address;
assert.isNotNull(organizationAddress, 'Organization contract address should not be null.');

const tokenRulesSetup = await new TokenRulesSetup(auxiliaryWeb3);
const tokenRulesDeployTxResponse = await tokenRulesSetup.deploy(organizationAddress, mockToken, txOptions);
Expand Down
42 changes: 22 additions & 20 deletions test/integration/DirectTransfer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const chai = require('chai'),
Web3 = require('web3'),
Package = require('../../index'),
Mosaic = require('@openstfoundation/mosaic-tbd');
Mosaic = require('@openstfoundation/mosaic.js');

const TokenRulesSetup = Package.Setup.TokenRules,
UserSetup = Package.Setup.User,
Expand All @@ -16,7 +16,6 @@ const TokenRulesSetup = Package.Setup.TokenRules,
{ dockerSetup, dockerTeardown } = require('./../../utils/docker');

const assert = chai.assert,
OrganizationHelper = Mosaic.ChainSetup.OrganizationHelper,
abiBinProvider = new AbiBinProvider();

let txOptions,
Expand Down Expand Up @@ -59,17 +58,16 @@ describe('Direct transfers between TH contracts', async function() {
});

it('Deploys Organization contract', async function() {
let orgHelper = new OrganizationHelper(auxiliaryWeb3, null);
const { Organization } = Mosaic.ContractInteract;
const orgConfig = {
deployer: deployerAddress,
owner: owner,
workers: worker,
workerExpirationHeight: '20000000'
owner,
admin: worker,
workers: [worker],
workerExpirationHeight: config.workerExpirationHeight
};

await orgHelper.setup(orgConfig);
organization = orgHelper.address;

const organizationContractInstance = await Organization.setup(auxiliaryWeb3, orgConfig);
organization = organizationContractInstance.address;
assert.isNotNull(organization, 'Organization contract address should not be null.');
});

Expand Down Expand Up @@ -340,19 +338,23 @@ describe('Direct transfers between TH contracts', async function() {
});

it('Performs direct transfer of tokens', async function() {
const tokenHolder = new TokenHolder(auxiliaryWeb3, tokenHolderSender),
mockTokenAbi = mockTokenDeployerInstance.abiBinProvider.getABI('MockToken'),
contract = new auxiliaryWeb3.eth.Contract(mockTokenAbi, mockToken, txOptions);
const tokenHolder = new TokenHolder(auxiliaryWeb3, tokenHolderSender);
// MockToken instance is needed because for transfer. Transfer is not available in Mosaic.ContractInteract.EIP20Token
// Please update after transfer is exposed in Mosaic.js
const mockTokenAbi = mockTokenDeployerInstance.abiBinProvider.getABI('MockToken');
const mockContractInstance = new auxiliaryWeb3.eth.Contract(mockTokenAbi, mockToken, txOptions);

const eip20Instance = new Mosaic.ContractInteract.EIP20Token(auxiliaryWeb3, mockToken);

// Funding TH proxy with tokens.
const amount = config.tokenHolderBalance;
const txObject = contract.methods.transfer(tokenHolderSender, amount);
const txObject = mockContractInstance.methods.transfer(tokenHolderSender, amount);
await txObject.send(txOptions);

const initialTHProxyBalance = await contract.methods.balanceOf(tokenHolderSender).call();
const initialTHProxyBalance = await eip20Instance.balanceOf(tokenHolderSender);
const transferTos = [tokenHolderFirstReceiver, tokenHolderSecondReceiver];
const firstReceiverInitialBalance = await contract.methods.balanceOf(tokenHolderFirstReceiver).call();
const secondReceiverInitialBalance = await contract.methods.balanceOf(tokenHolderSecondReceiver).call();
const firstReceiverInitialBalance = await eip20Instance.balanceOf(tokenHolderFirstReceiver);
const secondReceiverInitialBalance = await eip20Instance.balanceOf(tokenHolderSecondReceiver);
const transferAmounts = [20, 10];

const directTransferExecutable = tokenRulesObject.getDirectTransferExecutableData(transferTos, transferAmounts);
Expand All @@ -373,9 +375,9 @@ describe('Direct transfers between TH contracts', async function() {

await tokenHolder.executeRule(tokenRulesAddress, directTransferExecutable, nonce, vrs.r, vrs.s, vrs.v, txOptions);

const finalTHProxyBalance = await contract.methods.balanceOf(tokenHolderSender).call(),
firstReceiverFinalBalance = await contract.methods.balanceOf(tokenHolderFirstReceiver).call(),
secondReceiverFinalBalance = await contract.methods.balanceOf(tokenHolderSecondReceiver).call(),
const finalTHProxyBalance = await eip20Instance.balanceOf(tokenHolderSender),
firstReceiverFinalBalance = await eip20Instance.balanceOf(tokenHolderFirstReceiver),
secondReceiverFinalBalance = await eip20Instance.balanceOf(tokenHolderSecondReceiver),
firstReceiverExpectedBalance = parseInt(firstReceiverInitialBalance) + transferAmounts[0],
secondReceiverExpectedBalance = parseInt(secondReceiverInitialBalance) + transferAmounts[1];

Expand Down
20 changes: 9 additions & 11 deletions test/integration/WalletOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const chai = require('chai'),
Package = require('../../index'),
abiDecoder = require('abi-decoder'),
MockContractsDeployer = require('../utils/MockContractsDeployer'),
Mosaic = require('@openstfoundation/mosaic-tbd'),
Mosaic = require('@openstfoundation/mosaic.js'),
config = require('../utils/configReader');

const TokenRulesSetup = Package.Setup.TokenRules,
Expand All @@ -14,8 +14,7 @@ const TokenRulesSetup = Package.Setup.TokenRules,
TokenHolder = Package.Helpers.TokenHolder,
GnosisSafe = Package.Helpers.GnosisSafe;

const assert = chai.assert,
OrganizationHelper = Mosaic.ChainSetup.OrganizationHelper,
const { assert } = chai,
abiBinProvider = new AbiBinProvider();

const { dockerSetup, dockerTeardown } = require('./../../utils/docker');
Expand Down Expand Up @@ -64,17 +63,16 @@ describe('Wallet operations', async function() {
});

it('Should deploy Organization contract', async function() {
let orgHelper = new OrganizationHelper(auxiliaryWeb3, null);
const { Organization } = Mosaic.ContractInteract;
const orgConfig = {
deployer: deployerAddress,
owner: owner,
workers: worker,
workerExpirationHeight: '20000000'
owner,
admin: worker,
workers: [worker],
workerExpirationHeight: config.workerExpirationHeight
};

await orgHelper.setup(orgConfig);
organization = orgHelper.address;

const organizationContractInstance = await Organization.setup(auxiliaryWeb3, orgConfig);
organization = organizationContractInstance.address;
assert.isNotNull(organization, 'Organization contract address should not be null.');
});

Expand Down
3 changes: 2 additions & 1 deletion test/utils/configReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ ConfigReader.prototype = {
requiredPriceOracleDecimals: 18,
sessionKeySpendingLimit: 1000000,
sessionKeyExpirationHeight: 100000000000,
auxiliaryPort: 8546
auxiliaryPort: 8546,
workerExpirationHeight: '20000000'
};

module.exports = new ConfigReader();