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

Upgrade test contracts to 0.5.0 and fix all resulting problems #1465

Merged
merged 4 commits into from
Nov 28, 2018
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
21 changes: 9 additions & 12 deletions packages/truffle-debugger/test/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const debug = debugModule("test:ast");
import { assert } from "chai";

import Ganache from "ganache-cli";
import Web3 from "web3";

import { prepareContracts } from "./helpers";
import Debugger from "lib/debugger";
Expand All @@ -13,10 +12,10 @@ import ast from "lib/ast/selectors";
import solidity from "lib/solidity/selectors";
import trace from "lib/trace/selectors";

import { getRange, findRange, rangeNodes } from "lib/ast/map";
import { getRange } from "lib/ast/map";

const __VARIABLES = `
pragma solidity ^0.4.18;
pragma solidity ~0.5;
Copy link
Contributor

Choose a reason for hiding this comment

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

These of course are necessary


contract Variables {
event Result(uint256 result);
Expand Down Expand Up @@ -44,22 +43,19 @@ contract Variables {
}
`;


let sources = {
"Variables.sol": __VARIABLES
};

describe("AST", function() {
var provider;
var web3;

var abstractions;
var artifacts;
var files;

before("Create Provider", async function() {
provider = Ganache.provider({seed: "debugger", gasLimit: 7000000});
web3 = new Web3(provider);
provider = Ganache.provider({ seed: "debugger", gasLimit: 7000000 });
});

before("Prepare contracts and artifacts", async function() {
Expand Down Expand Up @@ -93,23 +89,24 @@ describe("AST", function() {

let node = session.view(ast.current.node);

let [ nodeStart, nodeLength ] = getRange(node);
let [nodeStart, nodeLength] = getRange(node);
let nodeEnd = nodeStart + nodeLength;

let pointer = session.view(ast.current.pointer);

assert.isAtMost(
nodeStart, start,
nodeStart,
start,
`Node ${pointer} at should not begin after instruction source range`
);
assert.isAtLeast(
nodeEnd, end,
nodeEnd,
end,
`Node ${pointer} should not end after source`
);

session.stepNext();
} while(!session.view(trace.finished));

} while (!session.view(trace.finished));
});
});
});
7 changes: 5 additions & 2 deletions packages/truffle-debugger/test/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Debugger from "lib/debugger";
import sessionSelector from "lib/session/selectors";

const __OUTER = `
pragma solidity ^0.4.18;
pragma solidity ~0.5;
Copy link
Contributor

Choose a reason for hiding this comment

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

👍


import "./InnerContract.sol";

Expand All @@ -33,7 +33,7 @@ contract OuterContract {
`;

const __INNER = `
pragma solidity ^0.4.18;
pragma solidity ~0.5;
Copy link
Contributor

Choose a reason for hiding this comment

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

👍


contract InnerContract {
event Inner();
Expand Down Expand Up @@ -76,6 +76,7 @@ describe("Contexts", function() {

var abstractions;
var artifacts;
var files;

before("Create Provider", async function() {
provider = Ganache.provider({ seed: "debugger", gasLimit: 7000000 });
Expand All @@ -87,6 +88,7 @@ describe("Contexts", function() {
let prepared = await prepareContracts(provider, sources, migrations);
abstractions = prepared.abstractions;
artifacts = prepared.artifacts;
files = prepared.files;
});

it("returns view of addresses affected", async function() {
Expand All @@ -102,6 +104,7 @@ describe("Contexts", function() {

let bugger = await Debugger.forTx(txHash, {
provider,
files,
contracts: artifacts
});
debug("debugger ready");
Expand Down
187 changes: 104 additions & 83 deletions packages/truffle-debugger/test/data/decode/decoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,136 +5,155 @@ import faker from "faker";

import evm from "lib/evm/selectors";

import {
generateUints, describeDecoding
} from "./helpers";

import { generateUints, describeDecoding } from "./helpers";

const uints = generateUints();

function generateArray(length) {
return [...Array(length)]
.map(() => uints.next().value);
return [...Array(length)].map(() => uints.next().value);
}

const commonFixtures = [{
name: "multipleFullWordArray",
type: "uint[]",
value: generateArray(3) // takes up 3 whole words
}, {
name: "withinWordArray",
type: "uint16[]",
value: generateArray(10) // takes up >1/2 word
}, {
name: "multiplePartWordArray",
type: "uint64[]",
value: generateArray(9) // takes up 2.25 words
}, {
name: "inconvenientlyWordOffsetArray",
type: "uint240[]",
value: generateArray(3) // takes up ~2.8 words
}, {
name: "shortString",
type: "string",
value: "hello world"
}, {
name: "longString",
type: "string",
value: "solidity allocation is a fun lesson in endianness"
}];

const mappingFixtures = [{
name: "simpleMapping",
type: {
from: "uint256",
to: "uint256"
const commonFixtures = [
{
name: "multipleFullWordArray",
type: "uint[]",
value: generateArray(3) // takes up 3 whole words
},
value: {
...Object.assign({}, ...generateArray(5).map(
(value, idx) => ({ [idx]: value })
))
}
}, {
name: "numberedStrings",
type: {
from: "uint256",
to: "string"
{
name: "withinWordArray",
type: "uint16[]",
value: generateArray(10) // takes up >1/2 word
},
{
name: "multiplePartWordArray",
type: "uint64[]",
value: generateArray(9) // takes up 2.25 words
},
{
name: "inconvenientlyWordOffsetArray",
type: "uint240[]",
value: generateArray(3) // takes up ~2.8 words
},
{
name: "shortString",
type: "string",
value: "hello world"
},
value: {
...Object.assign({}, ...generateArray(7).map(
(value, idx) => ({ [value]: faker.lorem.slug(idx) })
))
{
name: "longString",
type: "string",
value: "solidity allocation is a fun lesson in endianness"
}
}, {
name: "stringsToStrings",
type: {
from: "string",
to: "string"
];

const mappingFixtures = [
{
name: "simpleMapping",
type: {
from: "uint256",
to: "uint256"
},
value: {
...Object.assign(
{},
...generateArray(5).map((value, idx) => ({ [idx]: value }))
)
}
},
value: {
...Object.assign({}, ...[0,1,2,3,4].map(
(idx) => ({ [faker.lorem.slug(idx)]: faker.lorem.slug(idx) })
))
{
name: "numberedStrings",
type: {
from: "uint256",
to: "string"
},
value: {
...Object.assign(
{},
...generateArray(7).map((value, idx) => ({
[value]: faker.lorem.slug(idx)
}))
)
}
},
{
name: "stringsToStrings",
type: {
from: "string",
to: "string"
},
value: {
...Object.assign(
{},
...[0, 1, 2, 3, 4].map(idx => ({
[faker.lorem.slug(idx)]: faker.lorem.slug(idx)
}))
)
}
}
}];
];

debug("mappingFixtures %O", mappingFixtures);

describe("Decoding", function() {

/*
* Storage Tests
*/
describeDecoding(
"Storage Variables", commonFixtures, evm.current.state.storage,
"Storage Variables",
commonFixtures,
evm.current.state.storage,

(contractName, fixtures) => {
return `pragma solidity ^0.4.23;
return `pragma solidity ~0.5;
Copy link
Contributor

Choose a reason for hiding this comment

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

👍


contract ${contractName} {

event Done();

// declarations
${fixtures
.map( ({type, name}) => `${type} ${name};` )
.join("\n ")}
${fixtures.map(({ type, name }) => `${type} ${name};`).join("\n ")}

function run() public {
${fixtures
.map( ({name, value}) => `${name} = ${JSON.stringify(value)};` )
.map(({ name, value }) => `${name} = ${JSON.stringify(value)};`)
.join("\n ")}

emit Done();
}
}
`; }
`;
}
);

describeDecoding(
"Mapping Variables", mappingFixtures, evm.current.state.storage,
"Mapping Variables",
mappingFixtures,
evm.current.state.storage,

(contractName, fixtures) => {
return `pragma solidity ^0.4.24;
return `pragma solidity ~0.5;
Copy link
Contributor

Choose a reason for hiding this comment

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

👍


contract ${contractName} {
event Done();

// declarations
${fixtures
.map( ({name, type: {from, to}}) => `mapping (${from} => ${to}) ${name};` )
.map(
({ name, type: { from, to } }) => `mapping (${from} => ${to}) ${name};`
)
.join("\n ")}

function run() public {
${fixtures
.map(
({name, type: {from}, value}) =>
Object.entries(value)
.map( ([k, v]) => (from === "string")
? `${name}["${k}"] = ${JSON.stringify(v)};`
: `${name}[${k}] = ${JSON.stringify(v)};`
)
.join("\n ")
.map(({ name, type: { from }, value }) =>
Object.entries(value)
.map(
([k, v]) =>
from === "string"
? `${name}["${k}"] = ${JSON.stringify(v)};`
: `${name}[${k}] = ${JSON.stringify(v)};`
)
.join("\n ")
)
.join("\n\n ")}

Expand All @@ -149,12 +168,14 @@ contract ${contractName} {
* Memory Tests
*/
describeDecoding(
"Memory Variables", commonFixtures, evm.current.state.memory,
"Memory Variables",
commonFixtures,
evm.current.state.memory,

(contractName, fixtures) => {
const separator = ";\n ";

function declareAssign({name, type, value}) {
function declareAssign({ name, type, value }) {
if (type.indexOf("[]") != -1) {
// array, must `new`
let declare = `${type} memory ${name} = new ${type}(${value.length})`;
Expand All @@ -165,7 +186,7 @@ contract ${contractName} {
}
}

return `pragma solidity ^0.4.23;
return `pragma solidity ~0.5;

contract ${contractName} {

Expand Down
Loading