This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Upgrade test contracts to 0.5.0 and fix all resulting problems #1465
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
import "./InnerContract.sol"; | ||
|
||
|
@@ -33,7 +33,7 @@ contract OuterContract { | |
`; | ||
|
||
const __INNER = ` | ||
pragma solidity ^0.4.18; | ||
pragma solidity ~0.5; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
contract InnerContract { | ||
event Inner(); | ||
|
@@ -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 }); | ||
|
@@ -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() { | ||
|
@@ -102,6 +104,7 @@ describe("Contexts", function() { | |
|
||
let bugger = await Debugger.forTx(txHash, { | ||
provider, | ||
files, | ||
contracts: artifacts | ||
}); | ||
debug("debugger ready"); | ||
|
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 |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ")} | ||
|
||
|
@@ -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})`; | ||
|
@@ -165,7 +186,7 @@ contract ${contractName} { | |
} | ||
} | ||
|
||
return `pragma solidity ^0.4.23; | ||
return `pragma solidity ~0.5; | ||
|
||
contract ${contractName} { | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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