UNPKG

@windingtree/wt-read-api

Version:

API to interact with the Winding Tree platform

78 lines (69 loc) 2.99 kB
const { deployLifToken } = require('./trust-clues'); const { AIRLINE_SEGMENT_ID, HOTEL_SEGMENT_ID } = require('../../src/constants'); const lib = require('zos-lib'); const Web3 = require('web3'); const provider = new Web3.providers.HttpProvider('http://localhost:8545'); const web3 = new Web3(provider); const deployApp = async () => { const lifTokenContract = await deployLifToken(); // Setup a local copy of zos package for wt-contracts const ZWeb3 = lib.ZWeb3; ZWeb3.initialize(web3.currentProvider); const Contracts = lib.Contracts; Contracts.setArtifactsDefaults({ gas: 6721975, gasPrice: 100000000000, }); const accounts = await web3.eth.getAccounts(); // setup the project with all the proxies const project = await lib.AppProject.fetchOrDeploy('wt-contracts', '0.0.1'); const Organization = Contracts.getFromNodeModules('@windingtree/wt-contracts', 'Organization'); const Entrypoint = Contracts.getFromNodeModules('@windingtree/wt-contracts', 'WindingTreeEntrypoint'); const OrganizationFactory = Contracts.getFromNodeModules('@windingtree/wt-contracts', 'OrganizationFactory'); const SegmentDirectory = Contracts.getFromNodeModules('@windingtree/wt-contracts', 'SegmentDirectory'); await project.setImplementation(Entrypoint, 'WindingTreeEntrypoint'); await project.setImplementation(Organization, 'Organization'); await project.setImplementation(OrganizationFactory, 'OrganizationFactory'); await project.setImplementation(SegmentDirectory, 'SegmentDirectory'); // setup the factory proxy const factory = await project.createProxy(OrganizationFactory, { initFunction: 'initialize', initArgs: [accounts[4], project.getApp().address], from: accounts[4], }); // setup the entrypoint proxy const entrypoint = await project.createProxy(Entrypoint, { initFunction: 'initialize', initArgs: [accounts[4], lifTokenContract.address, factory.address], from: accounts[4], }); const directories = {}; for (const segment of [AIRLINE_SEGMENT_ID, HOTEL_SEGMENT_ID]) { directories[segment] = await project.createProxy(SegmentDirectory, { initFunction: 'initialize', initArgs: [accounts[4], segment, lifTokenContract.address], from: accounts[4], }); } // Set entrypoint directories await entrypoint.methods.setSegment(AIRLINE_SEGMENT_ID, directories[AIRLINE_SEGMENT_ID].address).send({ from: accounts[4], gas: 60000000 }); await entrypoint.methods.setSegment(HOTEL_SEGMENT_ID, directories[HOTEL_SEGMENT_ID].address).send({ from: accounts[4], gas: 60000000 }); return { directories, factory, entrypoint, }; }; const mockAssociatedKeys = (sinon, wtLibsInstance, keys) => { wtLibsInstance.getOrganization = sinon.stub().callsFake(() => { return { hasAssociatedKey: sinon.stub().callsFake((signerAddress) => { return keys.indexOf(signerAddress) !== -1; }), }; }); }; module.exports = { deployApp, mockAssociatedKeys, };