Skip to content

Commit 90eb199

Browse files
committed
working
1 parent d4f8605 commit 90eb199

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed
File renamed without changes.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"test": "test"
88
},
99
"scripts": {
10-
"testnet": "npx ganache-cli-i ",
10+
"testnet": "npx ganache-cli -i 1234 -m='result chalk culture device mouse post focus marble nurse fire gun venue'",
1111
"compile": "yarn compile-old && yarn compile-new",
1212
"compile-old": "buidler compile --config buidler.config.4.js",
1313
"compile-new": "buidler compile",
@@ -44,6 +44,7 @@
4444
"@nomiclabs/buidler-solhint": "^1.0.0-beta.13",
4545
"@nomiclabs/buidler-truffle4": "^1.0.0-beta.13",
4646
"@nomiclabs/buidler-web3-legacy": "^1.0.0-beta.13",
47-
"@truffle/artifactor": "^4.0.33"
47+
"@truffle/artifactor": "^4.0.33",
48+
"ethers": "^4.0.37"
4849
}
4950
}

tasks/try-sign.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ task("sign", "sign")
3333
jsHashWithPrefix,
3434
sig2
3535
)
36-
console.log(result === other, result, other)
36+
if (result !== other) {
37+
throw new Error(`addresses don't match ${result} != ${other}`)
38+
}
3739

3840
result = await this.ecdsa.checkClover(other, sig2, tokenId, moves)
39-
console.log({result})
40-
41+
if (!result) {
42+
throw new Error(`result was false with checkClover`)
43+
}
44+
console.log(`Success!`)
4145
})

test/CloversController.test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const {
1010
_
1111
} = require('../helpers/utils')
1212

13+
var ethers = require('ethers')
1314
var {
1415
signMessage,
1516
toEthSignedMessageHash,
@@ -105,6 +106,13 @@ contract('CloversController.sol', async function(accounts) {
105106
{type:"address", value: recepient}
106107
)
107108

109+
const hashedMsgEthers = ethers.utils.solidityKeccak256([
110+
'uint256', 'bytes28[2]', 'uint256', 'bool', 'address'
111+
], [
112+
symmetricalTokenId1, symmetricalMoves1, symmetricalSymmetries1, keep1, recepient
113+
])
114+
115+
assert(hashedMsg1 === hashedMsgEthers, `hashes don't match ${hashedMsg1} != ${hashedMsgEthers}`)
108116

109117
const keep2 = true
110118
reversi = new Rev()
@@ -135,9 +143,17 @@ contract('CloversController.sol', async function(accounts) {
135143
assert(contractHashedMsg === hashedMsg1, "Hashed messages didn't match")
136144
})
137145
it('recover should work', async () => {
138-
signature1 = fixSignature(await web3.eth.sign(hashedMsg1, oracle));
146+
const foo = await web3.eth.sign(hashedMsg1, oracle)
147+
signature1 = fixSignature(foo);
139148
const jsHashWithPrefix = toEthSignedMessageHash(hashedMsg1)
140149

150+
const walletProvider = new ethers.Wallet('0xef09de2f5b5125b78652f07c8365b3dabd657611a2818715d73808d0df786f48')
151+
const ethersSig = await walletProvider.signMessage(ethers.utils.arrayify(hashedMsg1))
152+
assert(ethersSig === signature1, `signatures don't match ${ethersSig} !== ${signature1}`)
153+
154+
const ethersjsHashWithPrefix = ethers.utils.hashMessage(ethers.utils.arrayify(hashedMsg1))
155+
assert(ethersjsHashWithPrefix === jsHashWithPrefix, `hashes don't match ${ethersjsHashWithPrefix} !== ${jsHashWithPrefix}`)
156+
141157
// Recover the signer address from the generated message and signature.
142158
let result = await cloversController.recover(
143159
jsHashWithPrefix,

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3222,7 +3222,7 @@ [email protected]:
32223222
uuid "2.0.1"
32233223
xmlhttprequest "1.8.0"
32243224

3225-
ethers@^4.0.0-beta.1, ethers@^4.0.32:
3225+
ethers@^4.0.0-beta.1, ethers@^4.0.32, ethers@^4.0.37:
32263226
version "4.0.37"
32273227
resolved "https://registry.yarnpkg.com/ethers/-/ethers-4.0.37.tgz#dfa70d59498663878c5e4a977d14356660ca5b90"
32283228
integrity sha512-B7bDdyQ45A5lPr6k2HOkEKMtYOuqlfy+nNf8glnRvWidkDQnToKw1bv7UyrwlbsIgY2mE03UxTVtouXcT6Vvcw==

0 commit comments

Comments
 (0)