This repository has been archived by the owner on Jan 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for enforcing zosversion in ZosFiles
- Loading branch information
1 parent
83f3b5b
commit b87d251
Showing
7 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
packages/cli/test/mocks/networks/network-lib-with-contract.zos.test.json
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,16 @@ | ||
{ | ||
"version": "1.1.0", | ||
"zosversion": "2", | ||
"provider": { | ||
"address": "0x0000000000000000000000000000000000000010" | ||
}, | ||
"package": { | ||
"address": "0x0000000000000000000000000000000000000080" | ||
}, | ||
"contracts": { | ||
"Greeter": { | ||
"address": "0x1020", | ||
"bytecodeHash": "0x0001" | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/cli/test/mocks/networks/network-missing-zosversion.zos.test.json
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,3 @@ | ||
{ | ||
"version": "1.1.0" | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/cli/test/mocks/networks/network-unsupported-zosversion.zos.test.json
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,4 @@ | ||
{ | ||
"version": "1.1.0", | ||
"zosversion": "3" | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/cli/test/mocks/packages/package-missing-zosversion.zos.json
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,5 @@ | ||
{ | ||
"name": "Herbs", | ||
"version": "1.1.0", | ||
"contracts": {} | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/cli/test/mocks/packages/package-unsupported-zosversion.zos.json
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,6 @@ | ||
{ | ||
"name": "Herbs", | ||
"version": "1.1.0", | ||
"contracts": {}, | ||
"zosversion": "3" | ||
} |
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,37 @@ | ||
'use strict' | ||
require('../setup') | ||
|
||
const expect = require('chai').expect; | ||
|
||
import ZosNetworkFile from '../../src/models/files/ZosNetworkFile'; | ||
import ZosPackageFile from '../../src/models/files/ZosPackageFile'; | ||
|
||
contract('ZosNetworkFile', function() { | ||
beforeEach('loads parent package file', function () { | ||
this.appPackageFile = new ZosPackageFile('test/mocks/packages/package-empty.zos.json') | ||
this.libPackageFile = new ZosPackageFile('test/mocks/packages/package-empty-lib.zos.json') | ||
}) | ||
|
||
describe('constructor', function () { | ||
it('creates empty file', function () { | ||
const file = new ZosNetworkFile(this.appPackageFile, 'test', 'test/mocks/networks/new.test.json') | ||
file.data.zosversion.should.eq('2') | ||
}) | ||
|
||
it('loads existing file', function () { | ||
const file = new ZosNetworkFile(this.libPackageFile, 'test', 'test/mocks/networks/network-lib-with-contract.zos.test.json') | ||
file.data.zosversion.should.eq('2') | ||
file.packageAddress.should.eq('0x0000000000000000000000000000000000000080') | ||
file.providerAddress.should.eq('0x0000000000000000000000000000000000000010') | ||
file.contract('Greeter').address.should.eq('0x1020') | ||
}) | ||
|
||
it('fails to load missing zosversion', function () { | ||
expect(() => new ZosNetworkFile(this.appPackageFile, 'test', 'test/mocks/networks/network-missing-zosversion.zos.test.json')).to.throw(/zos version identifier not found/) | ||
}) | ||
|
||
it('fails to load unsupported zosversion', function () { | ||
expect(() => new ZosNetworkFile(this.appPackageFile, 'test', 'test/mocks/networks/network-unsupported-zosversion.zos.test.json')).to.throw(/Unrecognized zos version identifier 3/) | ||
}) | ||
}); | ||
}) |
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,31 @@ | ||
'use strict' | ||
require('../setup') | ||
|
||
const expect = require('chai').expect; | ||
|
||
import ZosPackageFile from '../../src/models/files/ZosPackageFile'; | ||
|
||
contract('ZosPackageFile', function() { | ||
describe('constructor', function () { | ||
it('creates empty file', function () { | ||
const file = new ZosPackageFile('test/mocks/packages/new.zos.json') | ||
file.data.zosversion.should.eq('2') | ||
}) | ||
|
||
it('loads existing file', function () { | ||
const file = new ZosPackageFile('test/mocks/packages/package-with-contracts.zos.json') | ||
file.data.zosversion.should.eq('2') | ||
file.name.should.eq('Herbs') | ||
file.version.should.eq('1.1.0') | ||
file.contract('Impl').should.eq('ImplV1') | ||
}) | ||
|
||
it('fails to load missing zosversion', function () { | ||
expect(() => new ZosPackageFile('test/mocks/packages/package-missing-zosversion.zos.json')).to.throw(/zos version identifier not found/) | ||
}) | ||
|
||
it('fails to load unsupported zosversion', function () { | ||
expect(() => new ZosPackageFile('test/mocks/packages/package-unsupported-zosversion.zos.json')).to.throw(/Unrecognized zos version identifier 3/) | ||
}) | ||
}); | ||
}) |