-
Notifications
You must be signed in to change notification settings - Fork 4k
Simple Contract Integrations #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 17 commits
00e2147
5a86527
5a93eb0
950e0ab
e756f47
0d9f844
6449227
5ebcd9b
ab126f6
7212256
27561c5
3275faa
ce94b44
3206df0
1110044
b5df6f0
14b8401
4ad554a
a1e47d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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(); | ||
| } | ||
| } |
| 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; | ||
| } | ||
| } |
| 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; | ||
| } | ||
| } |
| 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; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| pragma solidity ^0.5.0; | ||
|
|
||
| contract SelfAware { | ||
|
Contributor
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. lulz |
||
| function getMyAddress() public view returns(address) { | ||
| return address(this); | ||
| } | ||
| } | ||
| 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); | ||
| } | ||
| } |
| 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]; | ||
| } | ||
| } |
| 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; | ||
| } | ||
| } |
| 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' | ||
|
|
||
| /* Internal 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' | ||
|
Contributor
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. Btw one thing I forgot to mention is that technically if we were keeping to convention there'd be a comment for |
||
|
|
||
| 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('???') | ||
| }) | ||
|
Contributor
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. We've technically added timestamp in 4bf0c7e so this test could be enabled. |
||
| 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) | ||
| }) | ||
| }) | ||
| 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" | ||
| } | ||
| } |
| 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.
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.
Asked Ben about this, he said that it was just a type-o where he copied a test but forgot to update the name