forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple Contract Integrations (ethereum-optimism#16)
* fix timestamp * Changing examples package to be more generic (ethereum-optimism#64) * Changing examples package to be more generic * Updating default exec manager address * Add executable fullnode (ethereum-optimism#66) * Add executable fullnode * Add better logging with debug mode * Fix linting bug * Fixing output bytecode to not have 0x prepended (ethereum-optimism#70) * Add test for SLOAD and SSTORE shims in the govm (ethereum-optimism#39) We've forked Geth to intercept calls to the ExecutionManger contract in ethereum-optimism/go-ethereum#1. Add a a test that tests these changes. The test is a copy of the existing simple storage spec with some minor changes. Namely, we don't test that storage events were emitted when ExecutionManager#ovmSSTORE is called because our forked version of Geth doesn't emit events. This also makes a couple changes to test helper file: We pass in the address of the ExecutionManager to manuallyDeployOvmContract instead of the ExecutionManager itself. This allows us to pass in an address of an ExecutionManager that's already been deployed which we need to do in our new test. Replace getTransactionReceipt with waitForTransaction. When we were using the Javascript provider transactions would be mined more-or-less immediately. This means that getTransactionReceipt could be called immediately after sendTransaction and the transaction would be ready. When we're talking to a Geth node this may not be the case. Switching to waitForTransaction allows time for the transaction to be mined. * Truffle ERC-20 Example (ethereum-optimism#69) Working Truffle Example! Note: A small hack is required to get this to work -- documented in `packages/examples/truffle-config.js` Also adds: * Fix for nonces in ExecutionManager.sol * Gas limit fix setting it to the required 9_000_000 vs 5_000_000 in the fullnode * Util for adding padding to strings to make them of a certain length * Optional `add0x` param on `bufToHexStr(...)` * Lock around separate txs that are assumed to be run sequentially in DefaultWeb3Handler Co-authored-by: Mason Fischer <[email protected]> * Test that nonces are incremented on calls (ethereum-optimism#71) Before we were only incrementing nonces on CREATE. Wallets expect nonces to be incremented on CALLs aswell. This test tests that we are in fact inrementing nonces on CALLs aswell. Other changes: * Update the name of the executeCall test * Configuring OVM in separate truffle config as an easy example of side-by-side standard testing & ovm testing (ethereum-optimism#72) * pre rebase * move tests to fullnode pkg;2C * add txorigin test * finish dep struggles * typo Co-authored-by: Will Meister <[email protected]> Co-authored-by: Karl Floersch <[email protected]> Co-authored-by: Mason Fischer <[email protected]>
- Loading branch information
1 parent
a896fce
commit 00581e3
Showing
18 changed files
with
223 additions
and
13 deletions.
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
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
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
8 changes: 8 additions & 0 deletions
8
packages/rollup-full-node/test/contracts/transpiled/CallerGetter.sol
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
pragma solidity ^0.5.0; | ||
import "./CallerReturner.sol"; | ||
|
||
contract CallerGetter { | ||
function getMsgSenderFrom(address _callerReturner) public view returns(address) { | ||
return CallerReturner(_callerReturner).getMsgSender(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/rollup-full-node/test/contracts/transpiled/CallerReturner.sol
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pragma solidity ^0.5.0; | ||
|
||
contract CallerReturner { | ||
function getMsgSender() public view returns(address) { | ||
return msg.sender; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/rollup-full-node/test/contracts/transpiled/ExtCode.sol
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
pragma solidity ^0.5.0; | ||
|
||
contract ExtCode { | ||
function getExtCodeSizeOf(address _addr) public returns(uint) { | ||
uint toReturn; | ||
assembly { | ||
toReturn:= extcodesize(_addr) | ||
} | ||
return toReturn; | ||
} | ||
|
||
function getExtCodeHashOf(address _addr) public returns(bytes32) { | ||
bytes32 toReturn; | ||
assembly { | ||
toReturn:= extcodehash(_addr) | ||
} | ||
return toReturn; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/rollup-full-node/test/contracts/transpiled/OriginGetter.sol
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pragma solidity ^0.5.0; | ||
|
||
contract OriginGetter { | ||
function getTxOrigin() public view returns(address) { | ||
return tx.origin; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/rollup-full-node/test/contracts/transpiled/SelfAware.sol
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pragma solidity ^0.5.0; | ||
|
||
contract SelfAware { | ||
function getMyAddress() public view returns(address) { | ||
return address(this); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/rollup-full-node/test/contracts/transpiled/SimpleCaller.sol
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
pragma solidity ^0.5.0; | ||
import "./SimpleStorage.sol"; | ||
|
||
contract SimpleCaller { | ||
function doGetStorageCall(address _target, bytes32 key) public view returns(bytes32) { | ||
return SimpleStorage(_target).getStorage(key); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/rollup-full-node/test/contracts/transpiled/SimpleStorage.sol
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
pragma solidity ^0.5.0; | ||
|
||
contract SimpleStorage { | ||
mapping(bytes32 => bytes32) public builtInStorage; | ||
function setStorage(bytes32 key, bytes32 value) public { | ||
builtInStorage[key] = value; | ||
} | ||
|
||
function getStorage(bytes32 key) public view returns (bytes32) { | ||
return builtInStorage[key]; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/rollup-full-node/test/contracts/transpiled/TimeGetter.sol
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pragma solidity ^0.5.0; | ||
|
||
contract TimeGetter { | ||
function getTimestamp() public view returns(uint256) { | ||
return block.timestamp; | ||
} | ||
} |
File renamed without changes.
95 changes: 95 additions & 0 deletions
95
packages/rollup-full-node/test/integration/transpiler-integration.spec.ts
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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import '../../../rollup-dev-tools/test/setup' | ||
/* External Imports */ | ||
import { | ||
getLogger, | ||
remove0x, | ||
bufToHexString, | ||
hexStrToBuf, | ||
} from '@eth-optimism/core-utils' | ||
import { | ||
Address, | ||
formatBytecode, | ||
bufferToBytecode, | ||
} from '@eth-optimism/rollup-core' | ||
|
||
/* Contract Imports */ | ||
|
||
import * as SimpleStorage from '../contracts/build/transpiled/SimpleStorage.json' | ||
import * as SimpleCaller from '../contracts/build/transpiled/SimpleCaller.json' | ||
import * as SelfAware from '../contracts/build/transpiled/SelfAware.json' | ||
import * as CallerGetter from '../contracts/build/transpiled/CallerGetter.json' | ||
import * as OriginGetter from '../contracts/build/transpiled/OriginGetter.json' | ||
import * as CallerReturner from '../contracts/build/transpiled/CallerReturner.json' | ||
import * as TimeGetter from '../contracts/build/transpiled/TimeGetter.json' | ||
|
||
import { createMockProvider, getWallets, deployContract } from '../../' | ||
|
||
describe(`Various opcodes should be usable in combination with transpiler and full node`, () => { | ||
let provider | ||
let wallet | ||
|
||
beforeEach(async () => { | ||
provider = await createMockProvider() | ||
const wallets = getWallets(provider) | ||
wallet = wallets[0] | ||
}) | ||
|
||
afterEach(() => { | ||
provider.closeOVM() | ||
}) | ||
|
||
// TEST BASIC FUNCTIONALITIES | ||
|
||
it('should process cross-ovm-contract calls', async () => { | ||
const simpleStorage = await deployContract(wallet, SimpleStorage, [], []) | ||
const simpleCaller = await deployContract(wallet, SimpleCaller, [], []) | ||
|
||
const storageKey = '0x' + '01'.repeat(32) | ||
const storageValue = '0x' + '02'.repeat(32) | ||
|
||
await simpleStorage.setStorage(storageKey, storageValue) | ||
|
||
const res = await simpleCaller.doGetStorageCall( | ||
simpleStorage.address, | ||
storageKey | ||
) | ||
res.should.equal(storageValue) | ||
}) | ||
it('should work for address(this)', async () => { | ||
const selfAware = await deployContract(wallet, SelfAware, [], []) | ||
const deployedAddress: Address = selfAware.address | ||
const returnedAddress: Address = await selfAware.getMyAddress() | ||
deployedAddress.should.equal(returnedAddress) | ||
}) | ||
it.skip('should work for block.timestamp', async () => { | ||
// todo, once we handle timestamps, unskip this test | ||
const timeGetter = await deployContract(wallet, TimeGetter, [], []) | ||
const time = await timeGetter.getTimestamp() | ||
time._hex.should.equal('???') | ||
}) | ||
it('should work for msg.sender', async () => { | ||
const callerReturner = await deployContract(wallet, CallerReturner, [], []) | ||
const callerGetter = await deployContract(wallet, CallerGetter, [], []) | ||
const result = await callerGetter.getMsgSenderFrom(callerReturner.address) | ||
result.should.equal(callerGetter.address) | ||
}) | ||
it('should work for tx.origin', async () => { | ||
const originGetter = await deployContract(wallet, OriginGetter, [], []) | ||
const result = await originGetter.getTxOrigin() | ||
result.should.equal(wallet.address) | ||
}) | ||
|
||
// SIMPLE STORAGE TEST | ||
it('should set storage & retrieve the value', async () => { | ||
const simpleStorage = await deployContract(wallet, SimpleStorage, [], []) | ||
// Create some constants we will use for storage | ||
const storageKey = '0x' + '01'.repeat(32) | ||
const storageValue = '0x' + '02'.repeat(32) | ||
// Set storage with our new storage elements | ||
await simpleStorage.setStorage(storageKey, storageValue) | ||
// Get the storage | ||
const res = await simpleStorage.getStorage(storageKey) | ||
// Verify we got the value! | ||
res.should.equal(storageValue) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"sourcesPath": "./test/contracts/transpiled", | ||
"targetPath": "./test/contracts/build/transpiled", | ||
"npmPath": "../../node_modules", | ||
"solcVersion": "../../node_modules/@eth-optimism/solc-transpiler", | ||
"compilerOptions": { | ||
"outputSelection": { | ||
"*": { | ||
"*": ["*"] | ||
} | ||
}, | ||
"executionManagerAddress": "0xA193E42526F1FEA8C99AF609dcEabf30C1c29fAA" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"sourcesPath": "./test/contracts/untranspiled", | ||
"targetPath": "./test/contracts/build/untranspiled", | ||
"npmPath": "../../node_modules", | ||
"compilerOptions": { | ||
"outputSelection": { | ||
"*": { | ||
"*": ["*"] | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.