Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Internal improvement: Update compile interface #3252

Merged
merged 110 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from 89 commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
5bf7226
Change return format for compile/new
eggplantzzz Aug 12, 2020
b17b16f
Don't use promisify for required_sources and remove unneeded imports
eggplantzzz Aug 12, 2020
8afcc5e
Update how workflow-compile interfaces with compile methods and chang…
eggplantzzz Aug 12, 2020
dcb13aa
Update the subscriber for compile to take an array of compiler objects
eggplantzzz Aug 12, 2020
cc9bb6a
Update shim method to wrap compilation in an array
eggplantzzz Aug 12, 2020
8ee6279
Add some comments and change variable name in run and the legacy shim…
eggplantzzz Aug 12, 2020
3387c69
Update shimLegacy method
eggplantzzz Aug 12, 2020
e4a7146
Add some typings to @truffle/compile-common to be used later
eggplantzzz Aug 12, 2020
29b4f5e
Add some missed work
eggplantzzz Aug 12, 2020
2f0e3d6
Correct type
eggplantzzz Aug 12, 2020
89c86e4
Change old variable name
eggplantzzz Aug 12, 2020
09f8be1
Update some tests and return format in new/index
eggplantzzz Aug 12, 2020
fb11826
Update core/lib/test interface with workflow-compile
eggplantzzz Aug 13, 2020
387c999
Update variable name
eggplantzzz Aug 13, 2020
bee78d9
Only check the compiler name when contracts were compiled
eggplantzzz Aug 13, 2020
b7249a6
Only return compilations when something was compiled and remove check…
eggplantzzz Aug 13, 2020
b1f50fc
Do not return compilations from workflow-compile when nothing is comp…
eggplantzzz Aug 13, 2020
9c7c0c0
Update another test
eggplantzzz Aug 13, 2020
89d6897
Update some tests
eggplantzzz Aug 13, 2020
d22eb54
Update call to compile.with_dependencies
eggplantzzz Aug 14, 2020
3796fd1
Merge branch 'develop' of github.com:trufflesuite/truffle into update…
eggplantzzz Aug 14, 2020
0ab426a
Update exec to use new workflow-compile and add missing save step to …
eggplantzzz Aug 14, 2020
3bf5441
Create new compile method and update migrations to use new workflow-c…
eggplantzzz Aug 18, 2020
56ff7f1
Return object with undefined fields when no compilation takes place
eggplantzzz Aug 18, 2020
5ba9382
Merge branch 'develop' of github.com:trufflesuite/truffle into update…
eggplantzzz Aug 18, 2020
ac68c09
Update all packages to use new workflow-compile
eggplantzzz Aug 18, 2020
fb8e94d
Update another import
eggplantzzz Aug 18, 2020
0c6db6e
Only check the compiler name if compiler exists
eggplantzzz Aug 18, 2020
dcb780d
Correct use of compileAndSave for build command
eggplantzzz Aug 18, 2020
f7f2556
Update debugger test and the return value for compileAndSave
eggplantzzz Aug 18, 2020
d460373
Remove some garbage accidentally left in
eggplantzzz Aug 18, 2020
e708a09
Update some more tests
eggplantzzz Aug 18, 2020
5f868f4
Remove foler from workflow-compile and make the new stuff the default…
eggplantzzz Aug 19, 2020
8c5555e
Expose the legacy version of workflow-compile in core to avoid a brea…
eggplantzzz Aug 19, 2020
fa46412
Update one more import
eggplantzzz Aug 19, 2020
1ab328a
Update test import
eggplantzzz Aug 19, 2020
c4b86a1
Update Contracts.save to take all compilation ouput as an input
eggplantzzz Aug 19, 2020
7a28b74
Make new comile-solidity the default export
eggplantzzz Aug 19, 2020
425ac88
Update parser tests
eggplantzzz Aug 19, 2020
2763e5f
Rename with_dependencies to camel case
eggplantzzz Aug 19, 2020
f5c9a5e
Update test
eggplantzzz Aug 19, 2020
b06283d
Update a test
eggplantzzz Aug 19, 2020
7a87a45
Modify compile-vyper to no longer have a legacy interface
eggplantzzz Aug 19, 2020
0ec520f
Correct variable name in the contract definition and use the event sy…
eggplantzzz Aug 19, 2020
674ebc0
Update test
eggplantzzz Aug 19, 2020
b19077d
Update external-compile to return the new format and get rid of legac…
eggplantzzz Aug 20, 2020
027d301
Don't set default when indexing into supported compilers object
eggplantzzz Aug 20, 2020
50b48ea
Add some comments and change a variable name
eggplantzzz Aug 20, 2020
3d447c5
Update types in compile-common
eggplantzzz Aug 20, 2020
41e9587
Get rid of legacy shim
eggplantzzz Aug 20, 2020
5e2382e
Give compile packages a different, uniform structure - and probably b…
eggplantzzz Aug 21, 2020
c759530
Update some tests
eggplantzzz Aug 21, 2020
13dcb6f
Update another test
eggplantzzz Aug 21, 2020
b2ae5db
More tests
eggplantzzz Aug 21, 2020
9345c1a
Correctly receive return from Profiler.requiredSources
eggplantzzz Aug 21, 2020
5ba1273
Correct a scoping problem and adjust how workflow-compile accesses co…
eggplantzzz Aug 21, 2020
34360c7
Remove export
eggplantzzz Aug 22, 2020
4d2aa20
Get rid of 'this'
eggplantzzz Aug 22, 2020
fb87047
Update some imports
eggplantzzz Aug 22, 2020
4e0761b
Move legacy profiler stuff into legacy folder and update test
eggplantzzz Aug 24, 2020
4aaf8eb
Add shim to compile-common and use it in artifactor test
eggplantzzz Aug 24, 2020
10af081
Create namespace for shims and use it in the test
eggplantzzz Aug 24, 2020
068af14
Switch over to using the new code in compile-common
eggplantzzz Aug 24, 2020
38d45e5
Move some packages away from using the shims in compile-solidity/lega…
eggplantzzz Aug 24, 2020
ed21ffd
Correct mistake in save method
eggplantzzz Aug 24, 2020
4b601c4
Correct another mistake
eggplantzzz Aug 24, 2020
bdb9e97
Make run method return null when no sources are input
eggplantzzz Aug 25, 2020
f389422
Merge in develop branch
eggplantzzz Aug 26, 2020
3507350
Merge in develop
eggplantzzz Aug 26, 2020
eef842b
Don't call run when there are no sources in compile-solidity
eggplantzzz Aug 26, 2020
39b02d8
Move shims from workflow-compile to compile-common
eggplantzzz Aug 26, 2020
c291425
Move test
eggplantzzz Aug 26, 2020
2a6a45f
Reorganize shims and types
eggplantzzz Aug 27, 2020
2dc480b
Reorganize shims
eggplantzzz Aug 27, 2020
c6e350d
Change filename
eggplantzzz Aug 28, 2020
e9ac13f
Adjust calls to the shim
eggplantzzz Aug 28, 2020
1aa9764
Update library name
eggplantzzz Aug 28, 2020
17e1e76
Update calls to module
eggplantzzz Aug 28, 2020
0bb7bd6
Merge in develop branch
eggplantzzz Aug 31, 2020
09966b5
Merge pull request #3315 from trufflesuite/shim-relocation
eggplantzzz Aug 31, 2020
3461ee2
Correct mistake in calling compileAndSave with a callback
eggplantzzz Sep 8, 2020
e10b79a
Regenerate yarn.lock
eggplantzzz Sep 8, 2020
fd62489
Merge branch 'update-compile-interface' of github.com:trufflesuite/tr…
eggplantzzz Sep 8, 2020
997704d
Change function notation for compile packages
eggplantzzz Sep 8, 2020
e1e0bfa
Update naming for the shims
eggplantzzz Sep 8, 2020
dbbd191
Update some syntax and correcty import shims into the legacy shims file
eggplantzzz Sep 8, 2020
bb0a3ff
Remove unused shimContract function
eggplantzzz Sep 10, 2020
dc60c40
Globally change the conventional name for workflow-compile module
eggplantzzz Sep 10, 2020
169f636
Shim contracts in external-compile and write a couple of simple tests
eggplantzzz Sep 10, 2020
e69aa4f
Remove other unused shim
eggplantzzz Sep 11, 2020
72630a7
Wrap compilations in an object with compilations key
eggplantzzz Sep 11, 2020
c0b1329
Update code using the compiler packages
eggplantzzz Sep 11, 2020
65fac49
Merge in work from develop branch
eggplantzzz Sep 14, 2020
285104c
Update type
eggplantzzz Sep 14, 2020
0b9b5a2
Switch legacy code in compile-solidity to use the Profiler from compi…
eggplantzzz Sep 14, 2020
3ada5f6
Update some types
eggplantzzz Sep 14, 2020
de8cb6f
Standardize the method signature for compile and apply it in compiler…
eggplantzzz Sep 14, 2020
ab8810c
Change compile method to be named sources and be a part of the main C…
eggplantzzz Sep 14, 2020
c276883
Remove ts-ignore
eggplantzzz Sep 14, 2020
10865ce
Remove export
eggplantzzz Sep 14, 2020
f74be95
Move a couple of tests and fix them
eggplantzzz Sep 14, 2020
c6687c4
Update some method calls
eggplantzzz Sep 14, 2020
d41deef
Do not require paths as a field in options and correct some tests
eggplantzzz Sep 15, 2020
0c199af
Correct error in compile-vyper method and adjust some tests for the p…
eggplantzzz Sep 15, 2020
2e40cf9
Update call to sourcesWithDependencies
eggplantzzz Sep 15, 2020
a778f9a
Remove CompileFunction type and add sources method to Compiler interface
eggplantzzz Sep 15, 2020
68c944d
Remove comment
eggplantzzz Sep 15, 2020
84c23ba
Remove some more comments that were junking things up
eggplantzzz Sep 15, 2020
99df0e5
Change variable name and add some comments
eggplantzzz Sep 15, 2020
0addcaf
Update an interface
eggplantzzz Sep 15, 2020
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
104 changes: 55 additions & 49 deletions packages/artifactor/test/contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const path = require("path");
const fs = require("fs");
const Config = require("@truffle/config");
const requireNoCache = require("require-nocache")(module);
const Compile = require("@truffle/compile-solidity/legacy");
const { compile } = require("@truffle/compile-solidity");
const Ganache = require("ganache-core");
const Web3 = require("web3");
const { promisify } = require("util");
const { Shims } = require("@truffle/compile-common");
const tmp = require("tmp");
tmp.setGracefulCleanup();

Expand All @@ -19,14 +19,14 @@ describe("artifactor + require", () => {
const web3 = new Web3();
web3.setProvider(provider);

before(() => web3.eth.net.getId().then((id) => (networkID = id)));
before(() => web3.eth.net.getId().then(id => (networkID = id)));

before(async function () {
this.timeout(20000);

const sourcePath = path.join(__dirname, "Example.sol");
const sources = {
Example: fs.readFileSync(sourcePath, { encoding: "utf8" }),
Example: fs.readFileSync(sourcePath, { encoding: "utf8" })
};

const options = {
Expand All @@ -37,22 +37,23 @@ describe("artifactor + require", () => {
settings: {
optimizer: {
enabled: false,
runs: 200,
},
},
},
runs: 200
}
}
}
},
logger: {
log(stringToLog) {
this.loggedStuff = this.loggedStuff + stringToLog;
},
loggedStuff: "",
},
loggedStuff: ""
}
};
config = Config.default().with(options);

// Compile first
const result = await promisify(Compile)(sources, config);
const compilations = await compile(sources, config);
const { contracts } = compilations[0];

// Clean up after solidity. Only remove solidity's listener,
// which happens to be the first.
Expand All @@ -61,14 +62,19 @@ describe("artifactor + require", () => {
process.listeners("uncaughtException")[0] || (() => {})
);

const compiled = Schema.normalize(result["Example"]);
const exampleContract = contracts.find(
contract => contract.contractName === "Example"
);
const compiled = Schema.normalize(
Shims.NewToLegacy.forContract(exampleContract)
);
abi = compiled.abi;
bytecode = compiled.bytecode;

// Setup
const tempDir = tmp.dirSync({
unsafeCleanup: true,
prefix: "tmp-test-contract-",
prefix: "tmp-test-contract-"
});

const expectedFilepath = path.join(tempDir.name, "Example.json");
Expand All @@ -82,9 +88,9 @@ describe("artifactor + require", () => {
bytecode,
networks: {
[`${networkID}`]: {
address: "0xe6e1652a0397e078f434d6dda181b218cfd42e01",
},
},
address: "0xe6e1652a0397e078f434d6dda181b218cfd42e01"
}
}
})
.then(() => {
const json = requireNoCache(expectedFilepath);
Expand All @@ -94,11 +100,11 @@ describe("artifactor + require", () => {
});

before(() =>
web3.eth.getAccounts().then((_accounts) => {
web3.eth.getAccounts().then(_accounts => {
accounts = _accounts;

Example.defaults({
from: accounts[0],
from: accounts[0]
});
})
);
Expand All @@ -108,33 +114,33 @@ describe("artifactor + require", () => {
assert(transactionHash, "transactionHash should be non-empty");
}));

it("should get and set values via methods and get values via .call", (done) => {
it("should get and set values via methods and get values via .call", done => {
let example;
Example.new(1, { gas: 3141592 })
.then((instance) => {
.then(instance => {
example = instance;
return example.value.call();
})
.then((value) => {
.then(value => {
assert.equal(value.valueOf(), 1, "Starting value should be 1");
return example.setValue(5);
})
.then(() => example.value.call())
.then((value) => {
.then(value => {
assert.equal(parseInt(value), 5, "Ending value should be five");
})
.then(done)
.catch(done);
});

it("shouldn't synchronize constant functions", (done) => {
it("shouldn't synchronize constant functions", done => {
let example;
Example.new(5, { gas: 3141592 })
.then((instance) => {
.then(instance => {
example = instance;
return example.getValue();
})
.then((value) => {
.then(value => {
assert.equal(
value.valueOf(),
5,
Expand All @@ -145,26 +151,26 @@ describe("artifactor + require", () => {
.catch(done);
});

it("should allow BigNumbers as input parameters, and not confuse them as transaction objects", (done) => {
it("should allow BigNumbers as input parameters, and not confuse them as transaction objects", done => {
// BigNumber passed on new()
let example = null;
Example.new("30", { gas: 3141592 })
.then((instance) => {
.then(instance => {
example = instance;
return example.value.call();
})
.then((value) => {
.then(value => {
assert.equal(parseInt(value), 30, "Starting value should be 30");
// BigNumber passed in a transaction.
return example.setValue("25", { gas: 3141592 });
})
.then(() => example.value.call())
.then((value) => {
.then(value => {
assert.equal(parseInt(value), 25, "Ending value should be twenty-five");
// BigNumber passed in a call.
return example.parrot.call(865);
})
.then((parrotValue) => {
.then(parrotValue => {
assert.equal(
parseInt(parrotValue),
865,
Expand All @@ -175,10 +181,10 @@ describe("artifactor + require", () => {
.catch(done);
});

it("should return transaction hash, logs and receipt when using synchronised transactions", (done) => {
it("should return transaction hash, logs and receipt when using synchronised transactions", done => {
let example = null;
Example.new("1", { gas: 3141592 })
.then((instance) => {
.then(instance => {
example = instance;
return example.triggerEvent();
})
Expand Down Expand Up @@ -213,17 +219,17 @@ describe("artifactor + require", () => {
it("should trigger the fallback function when calling sendTransaction()", () => {
let example = null;
return Example.new("1", { gas: 3141592 })
.then((instance) => {
.then(instance => {
example = instance;
return example.fallbackTriggered();
})
.then((triggered) => {
.then(triggered => {
assert(
triggered === false,
"Fallback should not have been triggered yet"
);
return example.sendTransaction({
value: web3.utils.toWei("1", "ether"),
value: web3.utils.toWei("1", "ether")
});
})
.then(
Expand All @@ -235,19 +241,19 @@ describe("artifactor + require", () => {
})
)
)
.then((balance) => {
.then(balance => {
assert(balance === web3.utils.toWei("1", "ether"));
});
});

it("should trigger the fallback function when calling send() (shorthand notation)", () => {
let example = null;
return Example.new("1", { gas: 3141592 })
.then((instance) => {
.then(instance => {
example = instance;
return example.fallbackTriggered();
})
.then((triggered) => {
.then(triggered => {
assert(
triggered === false,
"Fallback should not have been triggered yet"
Expand All @@ -263,12 +269,12 @@ describe("artifactor + require", () => {
})
)
)
.then((balance) => {
.then(balance => {
assert(balance === web3.utils.toWei("1", "ether"));
});
});

it("errors when setting an invalid provider", (done) => {
it("errors when setting an invalid provider", done => {
try {
Example.setProvider(null);
assert.fail("setProvider() should have thrown an error");
Expand All @@ -278,15 +284,15 @@ describe("artifactor + require", () => {
done();
});

it("creates a network object when an address is set if no network specified", (done) => {
it("creates a network object when an address is set if no network specified", done => {
const NewExample = contract({
abi,
bytecode,
bytecode
});

NewExample.setProvider(provider);
NewExample.defaults({
from: accounts[0],
from: accounts[0]
});

assert.equal(NewExample.network_id, null);
Expand All @@ -307,29 +313,29 @@ describe("artifactor + require", () => {
.catch(done);
});

it("doesn't error when calling .links() or .events() with no network configuration", (done) => {
it("doesn't error when calling .links() or .events() with no network configuration", done => {
const eventABI = {
anonymous: false,
inputs: [
{
indexed: true,
name: "nameHash",
type: "bytes32",
type: "bytes32"
},
{
indexed: true,
name: "releaseHash",
type: "bytes32",
},
type: "bytes32"
}
],
name: "PackageRelease",
type: "event",
type: "event"
};

const MyContract = contract({
contractName: "MyContract",
abi: [eventABI],
bytecode: "0x12345678",
bytecode: "0x12345678"
});

MyContract.setNetwork(5);
Expand Down
2 changes: 1 addition & 1 deletion packages/box/test/box.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe("@truffle/box Box", () => {
utils.downloadBox.restore();
});

it("calls the cleanup function if it is available", function(done) {
it("calls the cleanup function if it is available", function (done) {
Box.unbox(TRUFFLE_BOX_DEFAULT, destination, {}, config).catch(() => {
assert(cleanupCallback.called);
done();
Expand Down
4 changes: 4 additions & 0 deletions packages/compile-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
"scripts": {
"build": "tsc",
"prepare": "yarn build",
"test": "mocha -r ts-node/register test/*.ts",
"watch": "tsc -w"
},
"devDependencies": {
"@types/fs-extra": "^8.1.0",
"@types/mocha": "^5.2.7",
"typescript": "3.9.6"
},
"dependencies": {
"mocha": "8.0.1",
"ts-node": "8.10.2",
"@truffle/contract-schema": "^3.2.4",
"@truffle/resolver": "^6.0.16",
"fs-extra": "^8.1.0"
Expand Down
5 changes: 3 additions & 2 deletions packages/compile-common/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import { Profiler } from "./profiler";
export { Profiler };
export { Profiler } from "./profiler";
export * as Shims from "./shims";
export * from "./types";
Loading