protocol/packages/contract-artifacts/test/contract_artifacts_test.ts
Xianny bd228034fd
Add workflow for copying compiled artifacts to 0x/contract-artifacts (#1842)
The contract artifacts should remain as standard compiler output during development. Fields should only be removed/added prior to being published in `@0x/contract-artifacts`. This PR adds the `yarn transform` script to `@0x/contract-artifacts` to facilitate this. 

Going forward, `abi-gen-templates` will have to support both standard artifacts and modified artifacts if they diverge, since the templates are used for `contract-artifacts`/`abi-gen-wrappers` (modified artifact) *and* development in all the `contracts/*` packages (standard artifact).

This PR makes the following changes to `contract-artifacts`:
- remove `evm.bytecode.linkReferences` from all artifacts
- remove `evm.deployedBytecode` and `sourceTreeHashHex` from Coordinator artifact
- prettify all artifacts (whitespace only changes)
2019-06-17 11:00:53 -07:00

44 lines
1.9 KiB
TypeScript

import * as chai from 'chai';
import { get } from 'lodash';
import 'mocha';
import * as artifacts from '../src/index';
import { ObjectMap } from '../../types/lib';
import { FORBIDDEN_PROPERTIES, REQUIRED_PROPERTIES } from '../src/transform';
const expect = chai.expect;
describe('Contract Artifacts', () => {
it('should not include forbidden attributes', () => {
const forbiddenPropertiesByArtifact: { [name: string]: string[] } = {};
for (const [artifactName, artifact] of Object.entries(artifacts)) {
for (const forbiddenProperty of FORBIDDEN_PROPERTIES) {
const rejectedValue = get(artifact, forbiddenProperty);
if (rejectedValue) {
const previousForbidden = forbiddenPropertiesByArtifact[artifactName];
forbiddenPropertiesByArtifact[artifactName] = previousForbidden
? [...previousForbidden, forbiddenProperty]
: [forbiddenProperty];
}
}
}
expect(forbiddenPropertiesByArtifact).to.eql({});
});
it('should include all required attributes', () => {
const missingRequiredPropertiesByArtifact: ObjectMap<string[]> = {};
for (const [artifactName, artifact] of Object.entries(artifacts)) {
for (const requiredProperty of REQUIRED_PROPERTIES) {
const requiredValue = get(artifact, requiredProperty);
if (requiredValue === undefined || requiredValue === '') {
const previousMissing = missingRequiredPropertiesByArtifact[artifactName];
missingRequiredPropertiesByArtifact[artifactName] = previousMissing
? [...previousMissing, requiredProperty]
: [requiredProperty];
}
}
}
expect(missingRequiredPropertiesByArtifact).to.eql({});
});
});