forked from zeppelinos/zos-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fail with explicit error when creating proxy for missing stdlib (zepp…
…elinos#322) * Fail with explicit error when creating proxy for missing stdlib Creating a proxy for a contract that belongs to an stdlib that was linked, but that link was not pushed to the network, would yield a "VM Revert" error. Now it explains that the stdlib is linked but a push is missing. * Improve error handling in check methods of network base controller
- Loading branch information
1 parent
edef540
commit b1a4d0a
Showing
5 changed files
with
120 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
'use strict' | ||
require('../setup') | ||
|
||
import sinon from 'sinon'; | ||
|
||
import * as add from '../../src/scripts/add'; | ||
import * as addAll from '../../src/scripts/add-all'; | ||
import * as push from '../../src/scripts/push'; | ||
import * as runWithTruffle from '../../src/utils/runWithTruffle' | ||
import Session from '../../src/models/network/Session' | ||
import program from '../../src/bin/program'; | ||
|
||
contract('add command', function() { | ||
|
||
it('should call add script with an alias and a filename', function(done) { | ||
var addFake = sinon.fake(function () { | ||
expect(addFake.calledOnce).to.equal(true) | ||
expect(addFake.calledWithExactly({ contractsData: [ { name: 'ImplV1', alias: 'Impl' } ] })).to.equal(true) | ||
addStub.restore() | ||
done() | ||
}) | ||
|
||
var addStub = sinon.stub(add, 'default').callsFake(addFake) | ||
program.parse(['node', 'zos', 'add', 'ImplV1:Impl', '--skip-compile']) | ||
}); | ||
|
||
it('should call add-all script if passed --all option', function(done) { | ||
var addAllFake = sinon.fake(function () { | ||
expect(addAllFake.calledOnce).to.equal(true) | ||
expect(addAllFake.calledWithExactly( { } )).to.equal(true) | ||
addAllStub.restore() | ||
done() | ||
}) | ||
|
||
var addAllStub = sinon.stub(addAll, 'default').callsFake(addAllFake) | ||
program.parse(['node', 'zos', 'add', '--all', '--skip-compile']) | ||
}); | ||
|
||
it('should call push script if passed --push option', function(done) { | ||
var addAllFake = sinon.fake() | ||
var runWithTruffleFake = function(script, options) { | ||
const { network, from, timeout } = Session.getOptions(options) | ||
const txParams = from ? { from } : {} | ||
|
||
if (!network) throw Error('A network name must be provided to execute the requested action.') | ||
script({ network, txParams }) | ||
} | ||
var pushFake = sinon.fake(function () { | ||
expect(pushFake.calledOnce).to.equal(true) | ||
expect(pushFake.calledWithExactly({ deployStdlib: undefined, reupload: undefined, network: 'test', txParams: {} })).to.equal(true) | ||
addAllStub.restore() | ||
pushStub.restore() | ||
runWithTruffleStub.restore() | ||
done() | ||
}) | ||
|
||
var addAllStub = sinon.stub(addAll, 'default').callsFake(addAllFake) | ||
var pushStub = sinon.stub(push, 'default').callsFake(pushFake) | ||
var runWithTruffleStub = sinon.stub(runWithTruffle, 'default').callsFake(runWithTruffleFake) | ||
|
||
program.parse(['node', 'zos', 'add', '--all', '--push', 'test', '--skip-compile']) | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,7 @@ contract('create script', function([_, owner]) { | |
|
||
it('should refuse to create a proxy for an undefined contract', async function() { | ||
await createProxy({ contractAlias: 'NotExists', network, txParams, networkFile: this.networkFile }) | ||
.should.be.rejectedWith('Contract NotExists not found in application or stdlib'); | ||
.should.be.rejectedWith(/Contract NotExists not found/); | ||
}); | ||
|
||
it('should refuse to create a proxy for a lib project', async function() { | ||
|
@@ -148,11 +148,26 @@ contract('create script', function([_, owner]) { | |
|
||
it('should create a proxy for a stdlib contract', async function () { | ||
await createProxy({ contractAlias: 'Greeter', network, txParams, networkFile: this.networkFile }); | ||
|
||
await assertProxy(this.networkFile, 'Greeter', { version }); | ||
}); | ||
}); | ||
|
||
describe('with unpushed stdlib link', function () { | ||
beforeEach('setting stdlib', async function () { | ||
await linkStdlib({ stdlibNameVersion: '[email protected]', packageFile: this.packageFile }); | ||
}); | ||
|
||
it('should refuse create a proxy for a stdlib contract', async function () { | ||
await createProxy({ contractAlias: 'Greeter', network, txParams, networkFile: this.networkFile }) | ||
.should.be.rejectedWith(/Contract Greeter is provided by mock-stdlib but it was not deployed to the network/) | ||
}); | ||
}); | ||
|
||
it('should refuse to create a proxy for an undefined contract', async function() { | ||
await createProxy({ contractAlias: 'NotExists', network, txParams, networkFile: this.networkFile }) | ||
.should.be.rejectedWith(/Contract NotExists not found/); | ||
}); | ||
|
||
describe('with local modifications', function () { | ||
beforeEach('changing local network file to have a different bytecode', async function () { | ||
const contracts = this.networkFile.contracts | ||
|