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

Allow non-numeric immutable keys in contract-schema and add test of Yul immutable recognition #4746

Merged
merged 2 commits into from
Feb 17, 2022
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
33 changes: 15 additions & 18 deletions packages/contract-schema/spec/contract-object.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,26 +151,23 @@
},
"ImmutableReferences": {
"type": "object",
"patternProperties": {
"[1-9][0-9]*": {
"type": "array",
"items": {
"type": "object",
"properties": {
"start": {
"type": "integer",
"minimum": 0
},
"length": {
"type": "integer",
"minimum": 0
}
"additionalProperties": {
"type": "array",
"items": {
"type": "object",
"properties": {
"start": {
"type": "integer",
"minimum": 0
},
"additionalProperties": false
}
"length": {
"type": "integer",
"minimum": 0
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
},
"GeneratedSources": {
"type": "array",
Expand Down
51 changes: 50 additions & 1 deletion packages/debugger/test/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,37 @@ contract Created {
}
`;

const __YUL_IMMUTABLE = `
object "YulImmutableTest" {
code {
let size := datasize("runtime")
let offset := dataoffset("runtime")
setimmutable(offset, "secret", 1)
datacopy(0, offset, size)
return(0, size)
}
object "runtime" {
code {
mstore(
0,
xor(
loadimmutable("secret"),
linkersymbol("project:/contracts/ImmutableTest.sol:TestLibrary")
)
)
return(0, 0x20)
}
}
}
`;

const __MIGRATION = `
let OuterContract = artifacts.require("OuterContract");
let InnerContract = artifacts.require("InnerContract");
let ImmutableTest = artifacts.require("ImmutableTest");
let TestLibrary = artifacts.require("TestLibrary");
let CreationTest = artifacts.require("CreationTest");
let YulImmutableTest = artifacts.require("YulImmutableTest");

module.exports = async function(deployer) {
await deployer.deploy(InnerContract);
Expand All @@ -94,6 +119,8 @@ module.exports = async function(deployer) {
await deployer.link(TestLibrary, ImmutableTest);
await deployer.deploy(ImmutableTest);
await deployer.deploy(CreationTest);
await deployer.link(TestLibrary, YulImmutableTest);
await deployer.deploy(YulImmutableTest);
};
`;

Expand All @@ -105,7 +132,8 @@ let sources = {
"OuterLibrary.sol": __OUTER,
"InnerContract.sol": __INNER,
"ImmutableTest.sol": __IMMUTABLE,
"CreationTest.sol": __CREATION
"CreationTest.sol": __CREATION,
"YulImmutableTest.yul": __YUL_IMMUTABLE
};

describe("Contexts", function () {
Expand Down Expand Up @@ -199,6 +227,27 @@ describe("Contexts", function () {
assert.equal(affectedInstances[libraryAddress].contractName, "TestLibrary");
});

it("correctly identifies context in presence of linkersymbols and immutables (Yul)", async function () {
let ImmutableTest = await abstractions.YulImmutableTest.deployed();
let address = ImmutableTest.address;

let result = await ImmutableTest.sendTransaction({ data: "0x" });
let txHash = result.tx;

let bugger = await Debugger.forTx(txHash, {
provider,
compilations,
lightMode: true
});
debug("debugger ready");

let affectedInstances = bugger.view(sessionSelector.info.affectedInstances);
debug("affectedInstances: %o", affectedInstances);

assert.property(affectedInstances, address);
assert.equal(affectedInstances[address].contractName, "YulImmutableTest");
});

it("determines encoded constructor arguments for creations", async function () {
let CreationTest = await abstractions.CreationTest.deployed();
let address = CreationTest.address;
Expand Down
2 changes: 1 addition & 1 deletion packages/debugger/test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function prepareContracts(provider, sources = {}, migrations) {

config.compilers = {
solc: {
version: "0.8.9",
version: "0.8.12",
settings: {
optimizer: { enabled: false, runs: 200 },
Copy link
Member

@cds-amal cds-amal Feb 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not part of this PR's changes but I'm curious what this optimizer settings does, enabled is false and runs is 200?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yeah, runs does nothing if enabled is false. This is just how that's been, I've never bothered to alter that. I assume it's copied from the config defaults, which is also like that.

evmVersion: "london"
Expand Down