Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
69264d3a
Commit
69264d3a
authored
Sep 29, 2020
by
Kelvin Fichter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved over most library tests
parent
c7b37b40
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
855 additions
and
27 deletions
+855
-27
Lib_ECDSAUtils.sol
...ts/optimistic-ethereum/libraries/utils/Lib_ECDSAUtils.sol
+4
-1
Lib_MerkleUtils.sol
...s/optimistic-ethereum/libraries/utils/Lib_MerkleUtils.sol
+5
-0
TestLib_BytesUtils.sol
...cts/contracts/test-libraries/utils/TestLib_BytesUtils.sol
+2
-15
package.json
packages/contracts/package.json
+1
-1
Lib_OVMCodec.spec.ts
...racts/test/contracts/libraries/codec/Lib_OVMCodec.spec.ts
+18
-0
Lib_RLPWriter.spec.ts
...tracts/test/contracts/libraries/rlp/Lib_RLPWriter.spec.ts
+44
-0
Lib_EthMerkleTrie.spec.ts
...s/test/contracts/libraries/trie/Lib_EthMerkleTrie.spec.ts
+0
-0
Lib_MerkleTrie.spec.ts
...acts/test/contracts/libraries/trie/Lib_MerkleTrie.spec.ts
+0
-0
Lib_SecureMerkleTrie.spec.ts
...est/contracts/libraries/trie/Lib_SecureMerkleTrie.spec.ts
+0
-0
Lib_Bytes32Utils.spec.ts
...s/test/contracts/libraries/utils/Lib_Bytes32Utils.spec.ts
+9
-0
Lib_BytesUtils.spec.ts
...cts/test/contracts/libraries/utils/Lib_BytesUtils.spec.ts
+9
-0
Lib_ECDSAUtils.spec.ts
...cts/test/contracts/libraries/utils/Lib_ECDSAUtils.spec.ts
+9
-0
Lib_EthUtils.spec.ts
...racts/test/contracts/libraries/utils/Lib_EthUtils.spec.ts
+360
-0
index.ts
packages/contracts/test/data/index.ts
+7
-7
create2.test.json
packages/contracts/test/data/json/create2.test.json
+1
-1
Lib_Bytes32Utils.test.json
...racts/test/data/json/libraries/Lib_Bytes32Utils.test.json
+48
-0
Lib_BytesUtils.test.json
...ntracts/test/data/json/libraries/Lib_BytesUtils.test.json
+126
-0
Lib_ECDSAUtils.test.json
...ntracts/test/data/json/libraries/Lib_ECDSAUtils.test.json
+149
-0
Lib_RLPWriter.test.json
...ontracts/test/data/json/libraries/Lib_RLPWriter.test.json
+1
-1
safety-checker.test.json
packages/contracts/test/data/json/safety-checker.test.json
+1
-1
index.ts
packages/contracts/test/helpers/test-runner/index.ts
+1
-0
json-test-runner.ts
...es/contracts/test/helpers/test-runner/json-test-runner.ts
+37
-0
buffer-utils.ts
packages/contracts/test/helpers/utils/buffer-utils.ts
+23
-0
No files found.
packages/contracts/contracts/optimistic-ethereum/libraries/utils/Lib_ECDSAUtils.sol
View file @
69264d3a
...
...
@@ -35,15 +35,18 @@ library Lib_ECDSAUtils {
)
{
bytes32 messageHash;
uint8 v;
if (_isEthSignedMessage) {
messageHash = getEthSignedMessageHash(_message);
v = _v;
} else {
messageHash = getNativeMessageHash(_message);
v = (_v - uint8(_chainId) * 2) - 8;
}
return ecrecover(
messageHash,
(_v - uint8(_chainId) * 2) - 8
,
v
,
_r,
_s
);
...
...
packages/contracts/contracts/optimistic-ethereum/libraries/utils/Lib_MerkleUtils.sol
View file @
69264d3a
...
...
@@ -15,6 +15,11 @@ library Lib_MerkleUtils {
bytes32 _root
)
{
require(
_hashes.length > 0,
"Must provide at least one leaf hash."
);
if (_hashes.length == 1) {
return _hashes[0];
}
...
...
packages/contracts/contracts/test-libraries/utils/TestLib_BytesUtils.sol
View file @
69264d3a
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
/* Library Imports */
import { Lib_BytesUtils } from "../../optimistic-ethereum/libraries/utils/Lib_BytesUtils.sol";
...
...
@@ -39,24 +40,10 @@ library TestLib_BytesUtils {
);
}
function slice(
bytes memory _bytes,
uint256 _start
)
public
pure
returns (bytes memory)
{
return Lib_BytesUtils.slice(
_bytes,
_start
);
}
function toBytes32(
bytes memory _bytes
)
internal
public
pure
returns (bytes32)
{
...
...
packages/contracts/package.json
View file @
69264d3a
...
...
@@ -9,7 +9,7 @@
"build:contracts"
:
"buidler compile"
,
"build:copy"
:
"copyfiles -u 2
\"
contracts/optimistic-ethereum/**/*.sol
\"
\"
build/contracts
\"
"
,
"test"
:
"yarn run test:contracts"
,
"test:contracts"
:
"buidler test
\"
test/contracts/
OVM/chain/OVM_StateCommitmentChain
.spec.ts
\"
--show-stack-traces"
,
"test:contracts"
:
"buidler test
\"
test/contracts/
libraries/utils/Lib_EthUtils
.spec.ts
\"
--show-stack-traces"
,
"lint"
:
"tslint --format stylish --project ."
,
"fix"
:
"prettier --config prettier-config.json --write
\"
buidler.config.ts
\"
\"
{src,test}/**/*.ts
\"
"
,
"clean"
:
"rm -rf ./artifacts ./build ./cache"
...
...
packages/contracts/test/contracts/libraries/codec/Lib_OVMCodec.spec.ts
0 → 100644
View file @
69264d3a
/* tslint:disable:no-empty */
import
{
expect
}
from
'
../../../setup
'
describe
(
'
Lib_OVMCodec
'
,
()
=>
{
describe
(
'
decodeEOATransaction
'
,
()
=>
{
describe
(
'
when given a valid RLP-encoded transaction
'
,
()
=>
{
it
(
'
should return the decoded transaction struct
'
,
async
()
=>
{})
})
})
describe
(
'
encodeTransaction
'
,
()
=>
{
it
(
'
should ABI encode (packed) the given transaction
'
,
async
()
=>
{})
})
describe
(
'
hashTransaction
'
,
()
=>
{
it
(
'
should return the hash of the encoded transaction
'
,
async
()
=>
{})
})
})
packages/contracts/test/contracts/libraries/rlp/Lib_RLPWriter.spec.ts
0 → 100644
View file @
69264d3a
/* tslint:disable:no-empty */
import
{
expect
}
from
'
../../../setup
'
/* External Imports */
import
{
ethers
}
from
'
@nomiclabs/buidler
'
import
{
Contract
}
from
'
ethers
'
/* Internal Imports */
import
{
Lib_RLPWriter_TEST_JSON
}
from
'
../../../data
'
const
encode
=
async
(
Lib_RLPWriter
:
Contract
,
input
:
any
):
Promise
<
void
>
=>
{
if
(
Array
.
isArray
(
input
))
{
const
elements
=
await
Promise
.
all
(
input
.
map
(
async
(
el
)
=>
{
return
encode
(
Lib_RLPWriter
,
el
)
})
)
return
Lib_RLPWriter
.
encodeList
(
elements
)
}
else
if
(
Number
.
isInteger
(
input
))
{
return
Lib_RLPWriter
.
encodeUint
(
input
)
}
else
if
(
input
[
0
]
===
'
#
'
)
{
return
Lib_RLPWriter
.
encodeInt
(
input
.
slice
(
1
))
}
else
{
return
Lib_RLPWriter
.
encodeString
(
input
)
}
}
describe
(
'
Lib_RLPWriter
'
,
()
=>
{
let
Lib_RLPWriter
:
Contract
before
(
async
()
=>
{
Lib_RLPWriter
=
await
(
await
ethers
.
getContractFactory
(
'
TestLib_RLPWriter
'
)
).
deploy
()
})
describe
(
'
Official Ethereum RLP Tests
'
,
()
=>
{
for
(
const
[
key
,
test
]
of
Object
.
entries
(
Lib_RLPWriter_TEST_JSON
))
{
it
(
`should properly encode:
${
key
}
`
,
async
()
=>
{
expect
(
await
encode
(
Lib_RLPWriter
,
test
.
in
)).
to
.
equal
(
test
.
out
)
})
}
})
})
packages/contracts/test/contracts/libraries/trie/Lib_EthMerkleTrie.spec.ts
0 → 100644
View file @
69264d3a
packages/contracts/test/contracts/libraries/trie/Lib_MerkleTrie.spec.ts
0 → 100644
View file @
69264d3a
packages/contracts/test/contracts/libraries/trie/Lib_SecureMerkleTrie.spec.ts
0 → 100644
View file @
69264d3a
packages/contracts/test/contracts/libraries/utils/Lib_Bytes32Utils.spec.ts
0 → 100644
View file @
69264d3a
/* Internal Imports */
import
{
Lib_Bytes32Utils_TEST_JSON
}
from
'
../../../data
'
import
{
runJsonTest
}
from
'
../../../helpers
'
describe
(
'
Lib_Bytes32Utils
'
,
()
=>
{
describe
(
'
JSON tests
'
,
()
=>
{
runJsonTest
(
'
TestLib_Bytes32Utils
'
,
Lib_Bytes32Utils_TEST_JSON
)
})
})
packages/contracts/test/contracts/libraries/utils/Lib_BytesUtils.spec.ts
0 → 100644
View file @
69264d3a
/* Internal Imports */
import
{
Lib_BytesUtils_TEST_JSON
}
from
'
../../../data
'
import
{
runJsonTest
}
from
'
../../../helpers
'
describe
(
'
Lib_BytesUtils
'
,
()
=>
{
describe
(
'
JSON tests
'
,
()
=>
{
runJsonTest
(
'
TestLib_BytesUtils
'
,
Lib_BytesUtils_TEST_JSON
)
})
})
packages/contracts/test/contracts/libraries/utils/Lib_ECDSAUtils.spec.ts
0 → 100644
View file @
69264d3a
/* Internal Imports */
import
{
Lib_ECDSAUtils_TEST_JSON
}
from
'
../../../data
'
import
{
runJsonTest
}
from
'
../../../helpers
'
describe
(
'
Lib_ECDSAUtils
'
,
()
=>
{
describe
(
'
JSON tests
'
,
()
=>
{
runJsonTest
(
'
TestLib_ECDSAUtils
'
,
Lib_ECDSAUtils_TEST_JSON
)
})
})
packages/contracts/test/contracts/libraries/utils/Lib_EthUtils.spec.ts
0 → 100644
View file @
69264d3a
/* tslint:disable:no-empty */
import
{
expect
}
from
'
../../../setup
'
/* External Imports */
import
{
ethers
}
from
'
@nomiclabs/buidler
'
import
{
Contract
,
Signer
}
from
'
ethers
'
/* Internal Imports */
import
{
ZERO_ADDRESS
,
makeHexString
,
fromHexString
,
getHexSlice
,
}
from
'
../../../helpers
'
describe
(
'
Lib_EthUtils
'
,
()
=>
{
let
signer
:
Signer
before
(
async
()
=>
{
;[
signer
]
=
await
ethers
.
getSigners
()
})
let
Lib_EthUtils
:
Contract
before
(
async
()
=>
{
Lib_EthUtils
=
await
(
await
ethers
.
getContractFactory
(
'
TestLib_EthUtils
'
)
).
deploy
()
})
describe
(
'
getCode(address,uint256,uint256)
'
,
()
=>
{
describe
(
'
when the contract does not exist
'
,
()
=>
{
const
address
=
ZERO_ADDRESS
describe
(
'
when offset = 0
'
,
()
=>
{
const
offset
=
0
it
(
'
should return length zero bytes
'
,
async
()
=>
{
const
length
=
100
expect
(
await
Lib_EthUtils
[
'
getCode(address,uint256,uint256)
'
](
address
,
offset
,
length
)
).
to
.
equal
(
makeHexString
(
'
00
'
,
length
))
})
})
describe
(
'
when offset > 0
'
,
()
=>
{
const
offset
=
50
it
(
'
should return length zero bytes
'
,
async
()
=>
{
const
length
=
100
expect
(
await
Lib_EthUtils
[
'
getCode(address,uint256,uint256)
'
](
address
,
offset
,
length
)
).
to
.
equal
(
makeHexString
(
'
00
'
,
length
))
})
})
})
describe
(
'
when the account is an EOA
'
,
()
=>
{
let
address
:
string
before
(
async
()
=>
{
address
=
await
signer
.
getAddress
()
})
describe
(
'
when offset = 0
'
,
()
=>
{
const
offset
=
0
it
(
'
should return length zero bytes
'
,
async
()
=>
{
const
length
=
100
expect
(
await
Lib_EthUtils
[
'
getCode(address,uint256,uint256)
'
](
address
,
offset
,
length
)
).
to
.
equal
(
makeHexString
(
'
00
'
,
length
))
})
})
describe
(
'
when offset > 0
'
,
()
=>
{
const
offset
=
50
it
(
'
should return length zero bytes
'
,
async
()
=>
{
const
length
=
100
expect
(
await
Lib_EthUtils
[
'
getCode(address,uint256,uint256)
'
](
address
,
offset
,
length
)
).
to
.
equal
(
makeHexString
(
'
00
'
,
length
))
})
})
})
describe
(
'
when the contract exists
'
,
()
=>
{
let
address
:
string
let
code
:
string
let
codeLength
:
number
before
(
async
()
=>
{
address
=
Lib_EthUtils
.
address
code
=
await
ethers
.
provider
.
getCode
(
address
)
codeLength
=
fromHexString
(
code
).
length
})
describe
(
'
when offset = 0
'
,
()
=>
{
const
offset
=
0
describe
(
'
when length = 0
'
,
()
=>
{
const
length
=
0
it
(
'
should return empty
'
,
async
()
=>
{
expect
(
await
Lib_EthUtils
[
'
getCode(address,uint256,uint256)
'
](
address
,
offset
,
length
)
).
to
.
equal
(
'
0x
'
)
})
})
describe
(
'
when 0 < length < extcodesize(contract)
'
,
()
=>
{
let
length
:
number
before
(
async
()
=>
{
length
=
Math
.
floor
(
codeLength
/
2
)
})
it
(
'
should return N bytes from the start of code
'
,
async
()
=>
{
expect
(
await
Lib_EthUtils
[
'
getCode(address,uint256,uint256)
'
](
address
,
offset
,
length
)
).
to
.
equal
(
getHexSlice
(
code
,
offset
,
length
))
})
})
describe
(
'
when length = extcodesize(contract)
'
,
()
=>
{
let
length
:
number
before
(
async
()
=>
{
length
=
codeLength
})
it
(
'
should return the full contract code
'
,
async
()
=>
{
expect
(
await
Lib_EthUtils
[
'
getCode(address,uint256,uint256)
'
](
address
,
offset
,
length
)
).
to
.
equal
(
code
)
})
})
describe
(
'
when length > extcodesize(contract)
'
,
()
=>
{
let
length
:
number
before
(
async
()
=>
{
length
=
codeLength
*
2
})
it
(
'
should return the full contract code padded to length with zero bytes
'
,
async
()
=>
{
expect
(
await
Lib_EthUtils
[
'
getCode(address,uint256,uint256)
'
](
address
,
offset
,
length
)
).
to
.
equal
(
code
+
'
00
'
.
repeat
(
codeLength
))
})
})
})
describe
(
'
when 0 < offset < extcodesize(contract)
'
,
()
=>
{
let
offset
:
number
before
(
async
()
=>
{
offset
=
Math
.
floor
(
codeLength
/
2
)
})
describe
(
'
when length = 0
'
,
()
=>
{
const
length
=
0
it
(
'
should return empty
'
,
async
()
=>
{
expect
(
await
Lib_EthUtils
[
'
getCode(address,uint256,uint256)
'
](
address
,
offset
,
length
)
).
to
.
equal
(
'
0x
'
)
})
})
describe
(
'
when 0 < length < extcodesize(contract) - offset
'
,
()
=>
{
let
length
:
number
before
(
async
()
=>
{
length
=
Math
.
floor
((
codeLength
-
offset
)
/
2
)
})
it
(
'
should return the selected bytes
'
,
async
()
=>
{
expect
(
await
Lib_EthUtils
[
'
getCode(address,uint256,uint256)
'
](
address
,
offset
,
length
)
).
to
.
equal
(
getHexSlice
(
code
,
offset
,
length
))
})
})
describe
(
'
when length = extcodesize(contract) - offset
'
,
()
=>
{
let
length
:
number
before
(
async
()
=>
{
length
=
codeLength
-
offset
})
it
(
'
should return the selected bytes
'
,
async
()
=>
{
expect
(
await
Lib_EthUtils
[
'
getCode(address,uint256,uint256)
'
](
address
,
offset
,
length
)
).
to
.
equal
(
getHexSlice
(
code
,
offset
,
length
))
})
})
describe
(
'
when length > extcodesize(contract) - offset
'
,
()
=>
{
let
length
:
number
let
extraLength
:
number
before
(
async
()
=>
{
length
=
(
codeLength
-
offset
)
*
2
extraLength
=
length
-
(
codeLength
-
offset
)
})
it
(
'
should return the selected bytes padded to length with zero bytes
'
,
async
()
=>
{
expect
(
await
Lib_EthUtils
[
'
getCode(address,uint256,uint256)
'
](
address
,
offset
,
length
)
).
to
.
equal
(
getHexSlice
(
code
,
offset
,
codeLength
-
offset
)
+
'
00
'
.
repeat
(
extraLength
)
)
})
})
})
describe
(
'
offset >= extcodesize(contract)
'
,
()
=>
{
let
offset
:
number
before
(
async
()
=>
{
offset
=
codeLength
*
2
})
describe
(
'
when length = 0
'
,
()
=>
{
const
length
=
0
it
(
'
should return empty
'
,
async
()
=>
{
expect
(
await
Lib_EthUtils
[
'
getCode(address,uint256,uint256)
'
](
address
,
offset
,
length
)
).
to
.
equal
(
'
0x
'
)
})
})
describe
(
'
when length > 0
'
,
()
=>
{
let
length
:
number
before
(
async
()
=>
{
length
=
codeLength
*
2
})
it
(
'
should return length zero bytes
'
,
async
()
=>
{
expect
(
await
Lib_EthUtils
[
'
getCode(address,uint256,uint256)
'
](
address
,
offset
,
length
)
).
to
.
equal
(
makeHexString
(
'
00
'
,
length
))
})
})
})
})
})
describe
(
'
getCode(address)
'
,
()
=>
{
describe
(
'
when the contract does not exist
'
,
()
=>
{})
describe
(
'
when the account is an EOA
'
,
()
=>
{})
describe
(
'
when the contract exists
'
,
()
=>
{})
})
describe
(
'
getCodeSize
'
,
()
=>
{
describe
(
'
when the contract does not exist
'
,
()
=>
{})
describe
(
'
when the account is an EOA
'
,
()
=>
{})
describe
(
'
when the contract exists
'
,
()
=>
{})
})
describe
(
'
getCodeHash
'
,
()
=>
{
describe
(
'
when the contract does not exist
'
,
()
=>
{})
describe
(
'
when the account is an EOA
'
,
()
=>
{})
describe
(
'
when the contract exists
'
,
()
=>
{})
})
describe
(
'
createContract
'
,
()
=>
{
describe
(
'
it should create the contract
'
,
()
=>
{})
})
describe
(
'
getAddressForCREATE
'
,
()
=>
{
describe
(
'
when the nonce is zero
'
,
()
=>
{
describe
(
'
it should return the correct address
'
,
()
=>
{})
})
describe
(
'
when the nonce is > 0
'
,
()
=>
{
describe
(
'
it should return the correct address
'
,
()
=>
{})
})
})
describe
(
'
getAddressForCREATE2
'
,
()
=>
{
describe
(
'
when the bytecode is not empty
'
,
()
=>
{
describe
(
'
when the salt is not zero
'
,
()
=>
{
describe
(
'
it should return the correct address
'
,
()
=>
{})
})
describe
(
'
when the salt is zero
'
,
()
=>
{
describe
(
'
it should return the correct address
'
,
()
=>
{})
})
})
describe
(
'
when the bytecode is empty
'
,
()
=>
{
describe
(
'
when the salt is not zero
'
,
()
=>
{
describe
(
'
it should return the correct address
'
,
()
=>
{})
})
describe
(
'
when the salt is zero
'
,
()
=>
{
describe
(
'
it should return the correct address
'
,
()
=>
{})
})
})
})
})
packages/contracts/test/data/index.ts
View file @
69264d3a
import
{
create2Tests
}
from
'
./json/create2
.test.json
'
import
{
rlpTests
}
from
'
./json/rlp
.test.json
'
import
{
safetyCheckerTests
}
from
'
./json/safety-checker
.test.json
'
export
const
RLP_TEST_JSON
=
rlpTests
export
const
CREATE2_TEST_JSON
=
create2Tests
export
const
SAFETY_CHECKER_TEST_JSON
=
safetyCheckerTests
export
{
tests
as
Lib_RLPWriter_TEST_JSON
}
from
'
./json/libraries/Lib_RLPWriter
.test.json
'
export
{
tests
as
Lib_Bytes32Utils_TEST_JSON
}
from
'
./json/libraries/Lib_Bytes32Utils
.test.json
'
export
{
tests
as
Lib_BytesUtils_TEST_JSON
}
from
'
./json/libraries/Lib_BytesUtils
.test.json
'
export
{
tests
as
Lib_ECDSAUtils_TEST_JSON
}
from
'
./json/libraries/Lib_ECDSAUtils.test.json
'
export
{
tests
as
Lib_MerkleUtils_TEST_JSON
}
from
'
./json/libraries/Lib_MerkleUtils.test.json
'
export
{
tests
as
CREATE2_TEST_JSON
}
from
'
./json/create2.test.json
'
export
{
tests
as
SAFETY_CHECKER_TEST_JSON
}
from
'
./json/safety-checker.test.json
'
packages/contracts/test/data/json/create2.test.json
View file @
69264d3a
...
...
@@ -2,7 +2,7 @@
"source"
:
"https://eips.ethereum.org/EIPS/eip-1014"
,
"notes"
:
"added additional tests with more bytecode"
,
"date"
:
"2020-01-10"
,
"
create2T
ests"
:
{
"
t
ests"
:
{
"all zero values"
:
{
"address"
:
"0x0000000000000000000000000000000000000000"
,
"salt"
:
"0x0000000000000000000000000000000000000000000000000000000000000000"
,
...
...
packages/contracts/test/data/json/libraries/Lib_Bytes32Utils.test.json
0 → 100644
View file @
69264d3a
{
"tests"
:
{
"toBool"
:
{
"input bytes32 of 0"
:
{
"in"
:
[
"0x0000000000000000000000000000000000000000000000000000000000000000"
],
"out"
:
[
false
]
},
"input bytes32 of 1"
:
{
"in"
:
[
"0x0000000000000000000000000000000000000000000000000000000000000001"
],
"out"
:
[
true
]
},
"input bytes32 > 1"
:
{
"in"
:
[
"0x1212121212121212121212121212121212121212121212121212121212121212"
],
"out"
:
[
true
]
},
"input bytes32 > 1, last byte 0"
:
{
"in"
:
[
"0x1212121212121212121212121212121212121212121212121212121212121200"
],
"out"
:
[
true
]
}
},
"fromBool"
:
{
"input false"
:
{
"in"
:
[
false
],
"out"
:
[
"0x0000000000000000000000000000000000000000000000000000000000000000"
]
},
"input true"
:
{
"in"
:
[
true
],
"out"
:
[
"0x0000000000000000000000000000000000000000000000000000000000000001"
]
}
},
"toAddress"
:
{
"input bytes32 address"
:
{
"in"
:
[
"0x0000000000000000000000001212121212121212121212121212121212121212"
],
"out"
:
[
"0x1212121212121212121212121212121212121212"
]
},
"input full bytes32"
:
{
"in"
:
[
"0x1212121212121212121212121212121212121212121212121212121212121212"
],
"out"
:
[
"0x1212121212121212121212121212121212121212"
]
}
},
"fromAddress"
:
{
"input address"
:
{
"in"
:
[
"0x1212121212121212121212121212121212121212"
],
"out"
:
[
"0x1212121212121212121212121212121212121212000000000000000000000000"
]
}
}
}
}
packages/contracts/test/data/json/libraries/Lib_BytesUtils.test.json
0 → 100644
View file @
69264d3a
{
"tests"
:
{
"concat"
:
{
"two non-empty inputs"
:
{
"in"
:
[
"0x1234"
,
"0x5678"
],
"out"
:
[
"0x12345678"
]
},
"two empty inputs"
:
{
"in"
:
[
"0x"
,
"0x"
],
"out"
:
[
"0x"
]
},
"first empty, second non-empty"
:
{
"in"
:
[
"0x1234"
,
"0x"
],
"out"
:
[
"0x1234"
]
},
"first non-empty, second empty"
:
{
"in"
:
[
"0x"
,
"0x5678"
],
"out"
:
[
"0x5678"
]
}
},
"slice"
:
{
"start zero, length = 0"
:
{
"in"
:
[
"0x12345678"
,
0
,
0
],
"out"
:
[
"0x"
]
},
"start zero, length = input.length"
:
{
"in"
:
[
"0x12345678"
,
0
,
4
],
"out"
:
[
"0x12345678"
]
},
"start zero, length > 0 and length < input.length"
:
{
"in"
:
[
"0x12345678"
,
0
,
2
],
"out"
:
[
"0x1234"
]
},
"start zero, length > input.length"
:
{
"in"
:
[
"0x12345678"
,
0
,
5
],
"revert"
:
"Read out of bounds"
},
"start > 0 and <= input.length, length = 0"
:
{
"in"
:
[
"0x12345678"
,
2
,
0
],
"out"
:
[
"0x"
]
},
"start > 0 and <= input.length, length = input.length - start"
:
{
"in"
:
[
"0x12345678"
,
2
,
2
],
"out"
:
[
"0x5678"
]
},
"start > 0 and <= input.length, length < input.length - start"
:
{
"in"
:
[
"0x12345678"
,
2
,
1
],
"out"
:
[
"0x56"
]
},
"start > 0 and <= input.length, length > input.length - start"
:
{
"in"
:
[
"0x12345678"
,
2
,
3
],
"revert"
:
"Read out of bounds"
},
"start > input.length"
:
{
"in"
:
[
"0x12345678"
,
5
,
1
],
"revert"
:
"Read out of bounds"
}
},
"toBytes32"
:
{
"input.length < 32 bytes"
:
{
"in"
:
[
"0x1234"
],
"out"
:
[
"0x1234000000000000000000000000000000000000000000000000000000000000"
]
},
"input.length = 32 bytes"
:
{
"in"
:
[
"0x1234123412341234123412341234123412341234123412341234123412341234"
],
"out"
:
[
"0x1234123412341234123412341234123412341234123412341234123412341234"
]
},
"input.length > 32 bytes"
:
{
"in"
:
[
"0x12341234123412341234123412341234123412341234123412341234123412345678567856785678567856785678567856785678567856785678567856785678"
],
"out"
:
[
"0x1234123412341234123412341234123412341234123412341234123412341234"
]
}
},
"toUint256"
:
{
"input.length < 32 bytes"
:
{
"in"
:
[
"0x000000000000000000000000000000000000000000000000000000001234"
],
"out"
:
[
305397760
]
},
"input.length = 32 bytes"
:
{
"in"
:
[
"0x0000000000000000000000000000000000000000000000000000000000001234"
],
"out"
:
[
4660
]
},
"input.length > 32 bytes"
:
{
"in"
:
[
"0x00000000000000000000000000000000000000000000000000000000000012345678567856785678567856785678567856785678567856785678567856785678"
],
"out"
:
[
4660
]
}
},
"toNibbles"
:
{
"one byte"
:
{
"in"
:
[
"0xff"
],
"out"
:
[
"0x0f0f"
]
},
"two bytes"
:
{
"in"
:
[
"0xffff"
],
"out"
:
[
"0x0f0f0f0f"
]
},
"four bytes"
:
{
"in"
:
[
"0xffffffff"
],
"out"
:
[
"0x0f0f0f0f0f0f0f0f"
]
}
},
"fromNibbles"
:
{
"two nibbles"
:
{
"in"
:
[
"0x0f0f"
],
"out"
:
[
"0xff"
]
},
"four nibbles"
:
{
"in"
:
[
"0x0f0f0f0f"
],
"out"
:
[
"0xffff"
]
},
"eight nibbles"
:
{
"in"
:
[
"0x0f0f0f0f0f0f0f0f"
],
"out"
:
[
"0xffffffff"
]
}
},
"equal"
:
{
"same inputs"
:
{
"in"
:
[
"0x1234"
,
"0x1234"
],
"out"
:
[
true
]
},
"different inputs"
:
{
"in"
:
[
"0x1234"
,
"0x4567"
],
"out"
:
[
false
]
}
}
}
}
packages/contracts/test/data/json/libraries/Lib_ECDSAUtils.test.json
0 → 100644
View file @
69264d3a
{
"tests"
:
{
"recover"
:
{
"standard hash, valid signature"
:
{
"in"
:
[
"0xf83d80808094121212121212121212121212121212121212121280a0bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a6c8080"
,
false
,
"0xfc"
,
"0x057bf1c0edf0a9002a79f8c9b39683f6453a18e73e02364270a2b6ee8117f11a"
,
"0x5f8181365a222c7b05a84c29a29754e6a925952d3bf4bd65a6259ef37ee048e3"
,
"0x6c"
],
"out"
:
[
"0x17ec8597ff92C3F44523bDc65BF0f1bE632917ff"
]
},
"standard hash, invalid v parameter"
:
{
"in"
:
[
"0xf83d80808094121212121212121212121212121212121212121280a0bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a6c8080"
,
false
,
"0x00"
,
"0x057bf1c0edf0a9002a79f8c9b39683f6453a18e73e02364270a2b6ee8117f11a"
,
"0x5f8181365a222c7b05a84c29a29754e6a925952d3bf4bd65a6259ef37ee048e3"
,
"0x6c"
],
"out"
:
[
"0x0000000000000000000000000000000000000000"
]
},
"standard hash, invalid r parameter"
:
{
"in"
:
[
"0xf83d80808094121212121212121212121212121212121212121280a0bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a6c8080"
,
false
,
"0xfc"
,
"0x0000000000000000000000000000000000000000000000000000000000000000"
,
"0x5f8181365a222c7b05a84c29a29754e6a925952d3bf4bd65a6259ef37ee048e3"
,
"0x6c"
],
"out"
:
[
"0x0000000000000000000000000000000000000000"
]
},
"standard hash, invalid s parameter"
:
{
"in"
:
[
"0xf83d80808094121212121212121212121212121212121212121280a0bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a6c8080"
,
false
,
"0xfc"
,
"0x057bf1c0edf0a9002a79f8c9b39683f6453a18e73e02364270a2b6ee8117f11a"
,
"0x0000000000000000000000000000000000000000000000000000000000000000"
,
"0x6c"
],
"out"
:
[
"0x0000000000000000000000000000000000000000"
]
},
"standard hash, invalid chainid parameter"
:
{
"in"
:
[
"0xf83d80808094121212121212121212121212121212121212121280a0bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a6c8080"
,
false
,
"0xfc"
,
"0x057bf1c0edf0a9002a79f8c9b39683f6453a18e73e02364270a2b6ee8117f11a"
,
"0x5f8181365a222c7b05a84c29a29754e6a925952d3bf4bd65a6259ef37ee048e3"
,
"0x00"
],
"out"
:
[
"0x0000000000000000000000000000000000000000"
]
},
"standard hash, invalid message"
:
{
"in"
:
[
"0x0000000000000000000000000000000000000000000000000000000000000000"
,
false
,
"0xfc"
,
"0x057bf1c0edf0a9002a79f8c9b39683f6453a18e73e02364270a2b6ee8117f11a"
,
"0x5f8181365a222c7b05a84c29a29754e6a925952d3bf4bd65a6259ef37ee048e3"
,
"0x6c"
],
"out"
:
[
"0x1397890fcfC2D7563Aa01cE93A217b9809D3447B"
]
},
"eth signed message hash, valid signature"
:
{
"in"
:
[
"0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006c000000000000000000000000121212121212121212121212121212121212121200000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000020bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a"
,
true
,
"0x1c"
,
"0xe5a2edb71b6d76a8aacd59467d3063fd455ca13a4e9cb57da6f25849d40e4e2a"
,
"0x5465373d68d521845e3ffd2baf4c51f3d21c990914c09490b32ffc0b322dbf98"
,
"0x6c"
],
"out"
:
[
"0x17ec8597ff92C3F44523bDc65BF0f1bE632917ff"
]
},
"eth signed message hash, invalid v parameter"
:
{
"in"
:
[
"0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006c000000000000000000000000121212121212121212121212121212121212121200000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000020bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a"
,
true
,
"0x00"
,
"0xe5a2edb71b6d76a8aacd59467d3063fd455ca13a4e9cb57da6f25849d40e4e2a"
,
"0x5465373d68d521845e3ffd2baf4c51f3d21c990914c09490b32ffc0b322dbf98"
,
"0x6c"
],
"out"
:
[
"0x0000000000000000000000000000000000000000"
]
},
"eth signed message hash, invalid r parameter"
:
{
"in"
:
[
"0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006c000000000000000000000000121212121212121212121212121212121212121200000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000020bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a"
,
true
,
"0x1c"
,
"0x0000000000000000000000000000000000000000000000000000000000000000"
,
"0x5465373d68d521845e3ffd2baf4c51f3d21c990914c09490b32ffc0b322dbf98"
,
"0x6c"
],
"out"
:
[
"0x0000000000000000000000000000000000000000"
]
},
"eth signed message hash, invalid s parameter"
:
{
"in"
:
[
"0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006c000000000000000000000000121212121212121212121212121212121212121200000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000020bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a"
,
true
,
"0x1c"
,
"0xe5a2edb71b6d76a8aacd59467d3063fd455ca13a4e9cb57da6f25849d40e4e2a"
,
"0x0000000000000000000000000000000000000000000000000000000000000000"
,
"0x6c"
],
"out"
:
[
"0x0000000000000000000000000000000000000000"
]
},
"eth signed message hash, invalid message"
:
{
"in"
:
[
"0x0000000000000000000000000000000000000000000000000000000000000000"
,
true
,
"0x1c"
,
"0xe5a2edb71b6d76a8aacd59467d3063fd455ca13a4e9cb57da6f25849d40e4e2a"
,
"0x5465373d68d521845e3ffd2baf4c51f3d21c990914c09490b32ffc0b322dbf98"
,
"0x6c"
],
"out"
:
[
"0xf8bd1421f9D28C8F58f33B25a6faB16F3f89b749"
]
}
}
}
}
packages/contracts/test/data/json/
rlp
.test.json
→
packages/contracts/test/data/json/
libraries/Lib_RLPWriter
.test.json
View file @
69264d3a
...
...
@@ -3,7 +3,7 @@
"notes"
:
"Removed BigInt test, since ethers does not support integers over 10^16: https://github.com/ethers-io/ethers.js/issues/418"
,
"latestcommit"
:
"b2dcd19973637ac05e17646378dac9cbb2927075"
,
"date"
:
"2020-01-08"
,
"
rlpT
ests"
:
{
"
t
ests"
:
{
"emptystring"
:
{
"in"
:
""
,
"out"
:
"0x80"
...
...
packages/contracts/test/data/json/safety-checker.test.json
View file @
69264d3a
{
"
safetyCheckerT
ests"
:
{
"
t
ests"
:
{
"single opcode blacklisted: ADDRESS"
:
{
"in"
:
"0x30"
,
"out"
:
false
...
...
packages/contracts/test/helpers/test-runner/index.ts
View file @
69264d3a
export
*
from
'
./test-runner
'
export
*
from
'
./test.types
'
export
*
from
'
./json-test-runner
'
packages/contracts/test/helpers/test-runner/json-test-runner.ts
0 → 100644
View file @
69264d3a
import
{
expect
}
from
'
../../setup
'
/* External Imports */
import
{
ethers
}
from
'
@nomiclabs/buidler
'
import
{
Contract
,
BigNumber
}
from
'
ethers
'
export
const
runJsonTest
=
(
contractName
:
string
,
json
:
any
):
void
=>
{
let
contract
:
Contract
before
(
async
()
=>
{
contract
=
await
(
await
ethers
.
getContractFactory
(
contractName
)).
deploy
()
})
for
(
const
[
functionName
,
functionTests
]
of
Object
.
entries
(
json
))
{
describe
(
functionName
,
()
=>
{
for
(
const
[
key
,
test
]
of
Object
.
entries
(
functionTests
))
{
it
(
`should run test:
${
key
}
`
,
async
()
=>
{
if
(
test
.
revert
)
{
await
expect
(
contract
.
functions
[
functionName
](...
test
.
in
)).
to
.
be
.
reverted
}
else
{
expect
(
await
contract
.
functions
[
functionName
](...
test
.
in
)
).
to
.
deep
.
equal
(
test
.
out
.
map
((
out
:
any
)
=>
{
if
(
typeof
out
===
'
number
'
)
{
return
BigNumber
.
from
(
out
)
}
else
{
return
out
}
})
)
}
})
}
})
}
}
packages/contracts/test/helpers/utils/buffer-utils.ts
View file @
69264d3a
/* External Imports */
import
{
BigNumber
}
from
'
ethers
'
/**
* Converts a string or buffer to a '0x'-prefixed hex string.
* @param buf String or buffer to convert.
...
...
@@ -19,3 +22,23 @@ export const fromHexString = (str: string | Buffer): Buffer => {
return
Buffer
.
from
(
str
)
}
export
const
toHexString32
=
(
input
:
Buffer
|
string
|
number
,
padRight
=
false
):
string
=>
{
if
(
typeof
input
===
'
number
'
)
{
input
=
BigNumber
.
from
(
input
).
toHexString
()
}
input
=
toHexString
(
input
).
slice
(
2
)
return
'
0x
'
+
(
padRight
?
input
.
padEnd
(
64
,
'
0
'
)
:
input
.
padStart
(
64
,
'
0
'
))
}
export
const
getHexSlice
=
(
input
:
Buffer
|
string
,
start
:
number
,
length
:
number
):
string
=>
{
return
toHexString
(
fromHexString
(
input
).
slice
(
start
,
start
+
length
))
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment