Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

TestApp fix to work with multiple deps models #82

Merged
merged 8 commits into from
Sep 10, 2018
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
6 changes: 3 additions & 3 deletions packages/cli/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const version = 'v' + require('../package.json').version

// model objects
import TestApp from './models/TestApp'
import TestHelper from './models/TestHelper'
import ControllerFor from './models/local/ControllerFor'
import LocalAppController from './models/local/LocalAppController'
import LocalLibController from './models/local/LocalLibController'
Expand All @@ -11,10 +11,10 @@ import NetworkLibController from './models/network/NetworkLibController'

export {
version,
TestApp,
TestHelper,
ControllerFor,
LocalAppController,
LocalLibController,
NetworkAppController,
NetworkLibController
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import ControllerFor from '../models/network/ControllerFor';

/**
* Initializes a zOS application for testing, deploying it to the test network,
* Initializes a zOS application or stdlib project for testing, deploying it to the test network,
* along with its standard library (if specified)
* @param txParams optional txParams (from, gas, gasPrice) to use on every transaction
* @param networkFile optional `ZosNetworkFile` object to use, instead of zos.test.json
*/
export default async function testApp(txParams = {}, networkFile = undefined) {
export default async function(txParams = {}, networkFile = undefined) {
const controller = new ControllerFor('test', txParams, networkFile)
await controller.deployStdlib();
await controller.push();
return controller.app;
}
if (!controller.isLib) await controller.deployLibs()
await controller.push()

return controller.project
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "Herbs",
"version": "1.1.0",
"contracts": {
"Impl": "ImplV1"
},
"dependencies": {
"mock-stdlib-undeployed": "1.1.0",
"mock-stdlib-undeployed-2": "1.2.0"
}
}
52 changes: 0 additions & 52 deletions packages/cli/test/models/TestApp.test.js

This file was deleted.

115 changes: 115 additions & 0 deletions packages/cli/test/models/TestHelper.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
'use strict'

require('../setup')

import { Contracts } from 'zos-lib'
import TestHelper from '../../src/models/TestHelper'
import ZosPackageFile from "../../src/models/files/ZosPackageFile"

const ImplV1 = Contracts.getFromLocal('ImplV1')
const AnotherImpl = Contracts.getFromLocal('AnotherImplV1')

contract('TestHelper', function ([_, owner]) {
const txParams = { from: owner }
const projectName = 'Herbs'
const initialVersion = "1.1.0"

describe('for app project', function() {
beforeEach(async function () {
this.packageFile = new ZosPackageFile('test/mocks/packages/package-with-contracts-and-multiple-stdlibs.json')
this.networkFile = this.packageFile.networkFile('test')
this.app = await TestHelper(txParams, this.networkFile)
})

it('deploys all contracts', async function() {
const { app, directory, package: thePackage } = this.app

app.address.should.not.be.null
directory.address.should.not.be.null
thePackage.address.should.not.be.null
})

it('sets app at initial version', async function () {
(await this.app.getCurrentVersion()).should.eq(initialVersion)
})

it('registers initial version in package', async function () {
(await this.app.package.hasVersion(initialVersion)).should.be.true
})

it('initializes all app properties', async function () {
const { version, name } = this.app

version.should.eq(initialVersion)
name.should.eq(projectName)
})

it('returns the current directory', async function () {
(await this.app.getCurrentDirectory()).address.should.not.be.null
})

it('has dependencies deployed', async function () {
const dep1 = await this.app.getDependencyPackage('mock-stdlib-undeployed')
const dep2 = await this.app.getDependencyPackage('mock-stdlib-undeployed-2')

dep1.should.not.be.null
dep2.should.not.be.null
})

it('retrieves a mock from app', async function () {
const proxy = await this.app.createProxy(ImplV1, { contractName: 'Impl' })
const say = await proxy.say()

say.should.eq('V1')
})
})

describe('for lib project', function() {
beforeEach(async function () {
this.packageFile = new ZosPackageFile('test/mocks/packages/package-lib-with-contracts.zos.json')
this.networkFile = this.packageFile.networkFile('test')
this.lib = await TestHelper(txParams, this.networkFile)
this.directory = await this.lib.getCurrentDirectory()
})

it('deploys all contracts', async function() {
const { directory, package: thePackage } = this.lib

directory.address.should.not.be.null
thePackage.address.should.not.be.null
})

it('sets lib at initial version', async function () {
(await this.lib.getCurrentVersion()).should.eq(initialVersion)
})

it('registers initial version in package', async function () {
(await this.lib.package.hasVersion(initialVersion)).should.be.true
this.lib.version.should.eq(initialVersion)
})

it('has directory setted up', async function () {
this.directory.address.should.not.be.null
})

it('retrieves contracts in directory', async function() {
const impl = await this.directory.getImplementation('Impl')
const anotherImpl = await this.directory.getImplementation('AnotherImpl')

impl.should.not.be.null
anotherImpl.should.not.be.null
})

it('retrieves mocks from directory', async function() {
const impl = await this.directory.getImplementation('Impl')
const anotherImpl = await this.directory.getImplementation('AnotherImpl')
const implContract = ImplV1.at(impl)
const anotherImplContract = AnotherImpl.at(anotherImpl)
const implSay = await implContract.say()
const anotherImplSay = await anotherImplContract.say()

implSay.should.eq('V1')
anotherImplSay.should.eq('AnotherV1')
})
})
})