@@ -10,6 +10,7 @@ const {
10
10
_
11
11
} = require ( '../helpers/utils' )
12
12
13
+ var ethers = require ( 'ethers' )
13
14
var {
14
15
signMessage,
15
16
toEthSignedMessageHash,
@@ -105,6 +106,13 @@ contract('CloversController.sol', async function(accounts) {
105
106
{ type :"address" , value : recepient }
106
107
)
107
108
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 } ` )
108
116
109
117
const keep2 = true
110
118
reversi = new Rev ( )
@@ -135,9 +143,17 @@ contract('CloversController.sol', async function(accounts) {
135
143
assert ( contractHashedMsg === hashedMsg1 , "Hashed messages didn't match" )
136
144
} )
137
145
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 ) ;
139
148
const jsHashWithPrefix = toEthSignedMessageHash ( hashedMsg1 )
140
149
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
+
141
157
// Recover the signer address from the generated message and signature.
142
158
let result = await cloversController . recover (
143
159
jsHashWithPrefix ,
0 commit comments