@@ -2,26 +2,12 @@ const { expect } = require('chai');
2
2
const { ethers } = require ( 'hardhat' ) ;
3
3
const { loadFixture } = require ( '@nomicfoundation/hardhat-network-helpers' ) ;
4
4
5
- const { Permit, domainType } = require ( '@openzeppelin/contracts/test/helpers/eip712' ) ;
5
+ const { Permit } = require ( '@openzeppelin/contracts/test/helpers/eip712' ) ;
6
6
const { PersonalSignHelper, TypedDataSignHelper } = require ( '../../helpers/erc7739' ) ;
7
7
8
8
// Helper for ERC20Permit applications
9
9
const helper = TypedDataSignHelper . from ( { Permit } ) ;
10
10
11
- function domainComponentsType ( domain ) {
12
- return ethers . TypedDataEncoder . from ( { EIP712Domain : domainType ( domain ) } )
13
- . encodeType ( 'EIP712Domain' )
14
- . replace ( / E I P 7 1 2 D o m a i n \( ( .* ) \) / , ( _ , s ) => s ) ;
15
- }
16
-
17
- function domainComponentsBytes ( domain ) {
18
- return ethers . hexlify (
19
- ethers
20
- . getBytes ( ethers . TypedDataEncoder . from ( { EIP712Domain : domainType ( domain ) } ) . encodeData ( 'EIP712Domain' , domain ) )
21
- . slice ( 32 ) ,
22
- ) ;
23
- }
24
-
25
11
const fixture = async ( ) => {
26
12
const mock = await ethers . deployContract ( '$ERC7739Utils' ) ;
27
13
const domain = {
@@ -65,9 +51,9 @@ describe('ERC7739Utils', function () {
65
51
ethers . toBeHex ( contentDescr . length , 2 ) ,
66
52
] ) ;
67
53
68
- expect ( this . mock . $encodeTypedDataSig ( signature , appSeparator , contentsHash , contentDescr ) ) . to . eventually . equal (
69
- encoded ,
70
- ) ;
54
+ await expect (
55
+ this . mock . $encodeTypedDataSig ( signature , appSeparator , contentsHash , contentDescr ) ,
56
+ ) . to . eventually . equal ( encoded ) ;
71
57
} ) ;
72
58
} ) ;
73
59
@@ -85,7 +71,7 @@ describe('ERC7739Utils', function () {
85
71
ethers . toBeHex ( contentDescr . length , 2 ) ,
86
72
] ) ;
87
73
88
- expect ( this . mock . $decodeTypedDataSig ( encoded ) ) . to . eventually . deep . equal ( [
74
+ await expect ( this . mock . $decodeTypedDataSig ( encoded ) ) . to . eventually . deep . equal ( [
89
75
ethers . hexlify ( signature ) ,
90
76
appSeparator ,
91
77
contentsHash ,
@@ -95,7 +81,7 @@ describe('ERC7739Utils', function () {
95
81
96
82
it ( 'returns default empty values if the signature is too short' , async function ( ) {
97
83
const encoded = ethers . randomBytes ( 65 ) ; // DOMAIN_SEPARATOR (32 bytes) + CONTENTS (32 bytes) + CONTENTS_TYPE_LENGTH (2 bytes) - 1
98
- expect ( this . mock . $decodeTypedDataSig ( encoded ) ) . to . eventually . deep . equal ( [
84
+ await expect ( this . mock . $decodeTypedDataSig ( encoded ) ) . to . eventually . deep . equal ( [
99
85
'0x' ,
100
86
ethers . ZeroHash ,
101
87
ethers . ZeroHash ,
@@ -105,7 +91,7 @@ describe('ERC7739Utils', function () {
105
91
106
92
it ( 'returns default empty values if the length is invalid' , async function ( ) {
107
93
const encoded = ethers . concat ( [ ethers . randomBytes ( 64 ) , '0x3f' ] ) ; // Can't be less than 64 bytes
108
- expect ( this . mock . $decodeTypedDataSig ( encoded ) ) . to . eventually . deep . equal ( [
94
+ await expect ( this . mock . $decodeTypedDataSig ( encoded ) ) . to . eventually . deep . equal ( [
109
95
'0x' ,
110
96
ethers . ZeroHash ,
111
97
ethers . ZeroHash ,
@@ -118,7 +104,7 @@ describe('ERC7739Utils', function () {
118
104
it ( 'should produce a personal signature EIP-712 nested type' , async function ( ) {
119
105
const text = 'Hello, world!' ;
120
106
121
- expect ( this . mock . $personalSignStructHash ( ethers . hashMessage ( text ) ) ) . to . eventually . equal (
107
+ await expect ( this . mock . $personalSignStructHash ( ethers . hashMessage ( text ) ) ) . to . eventually . equal (
122
108
ethers . TypedDataEncoder . hashStruct ( 'PersonalSign' , PersonalSignHelper . types , PersonalSignHelper . prepare ( text ) ) ,
123
109
) ;
124
110
} ) ;
@@ -131,22 +117,36 @@ describe('ERC7739Utils', function () {
131
117
const contentsHash = helper . hashStruct ( 'Permit' , message . contents ) ;
132
118
const hash = helper . hashStruct ( 'TypedDataSign' , message ) ;
133
119
134
- expect (
120
+ const domainBytes = ethers . AbiCoder . defaultAbiCoder ( ) . encode (
121
+ [ 'bytes32' , 'bytes32' , 'uint256' , 'address' , 'bytes32' ] ,
122
+ [
123
+ ethers . id ( this . domain . name ) ,
124
+ ethers . id ( this . domain . version ) ,
125
+ this . domain . chainId ,
126
+ this . domain . verifyingContract ,
127
+ ethers . ZeroHash ,
128
+ ] ,
129
+ ) ;
130
+
131
+ await expect (
135
132
this . mock . $typedDataSignStructHash (
136
- helper . contentDescr ,
133
+ helper . contentsTypeName ,
134
+ ethers . Typed . string ( helper . contentDescr ) ,
137
135
contentsHash ,
138
- domainComponentsType ( this . domain ) ,
139
- domainComponentsBytes ( this . domain ) ,
136
+ domainBytes ,
140
137
) ,
141
138
) . to . eventually . equal ( hash ) ;
139
+ await expect (
140
+ this . mock . $typedDataSignStructHash ( helper . contentDescr , contentsHash , domainBytes ) ,
141
+ ) . to . eventually . equal ( hash ) ;
142
142
} ) ;
143
143
} ) ;
144
144
145
145
describe ( 'typedDataSignTypehash' , function ( ) {
146
146
it ( 'should match' , async function ( ) {
147
147
const typedDataSignType = ethers . TypedDataEncoder . from ( helper . allTypes ) . encodeType ( 'TypedDataSign' ) ;
148
148
149
- expect (
149
+ await expect (
150
150
this . mock . $typedDataSignTypehash (
151
151
helper . contentsTypeName ,
152
152
typedDataSignType . slice ( typedDataSignType . indexOf ( ')' ) + 1 ) ,
@@ -156,7 +156,6 @@ describe('ERC7739Utils', function () {
156
156
} ) ;
157
157
158
158
describe ( 'decodeContentsDescr' , function ( ) {
159
- const forbiddenFirstChars = 'abcdefghijklmnopqrstuvwxyz(' ;
160
159
const forbiddenChars = ', )\x00' ;
161
160
162
161
for ( const { descr, contentDescr, contentTypeName, contentType } of [ ] . concat (
@@ -181,16 +180,16 @@ describe('ERC7739Utils', function () {
181
180
contentDescr : 'SomeType' ,
182
181
contentTypeName : null ,
183
182
} ,
184
- forbiddenFirstChars . split ( '' ) . map ( char => ( {
185
- descr : ` should return nothing if starts with [${ char } ] (implicit)` ,
186
- contentDescr : ` ${ char } SomeType()` ,
183
+ {
184
+ descr : ' should return nothing if starts with [( ] (implicit)' ,
185
+ contentDescr : '( SomeType(address foo,uint256 bar)' ,
187
186
contentTypeName : null ,
188
- } ) ) ,
189
- forbiddenFirstChars . split ( '' ) . map ( char => ( {
190
- descr : ` should return nothing if starts with [${ char } ] (explicit)` ,
191
- contentDescr : ` ${ char } SomeType() ${ char } SomeType` ,
187
+ } ,
188
+ {
189
+ descr : ' should return nothing if starts with [( ] (explicit)' ,
190
+ contentDescr : '( SomeType(address foo,uint256 bar)( SomeType' ,
192
191
contentTypeName : null ,
193
- } ) ) ,
192
+ } ,
194
193
forbiddenChars . split ( '' ) . map ( char => ( {
195
194
descr : `should return nothing if contains [${ char } ] (implicit)` ,
196
195
contentDescr : `SomeType${ char } (address foo,uint256 bar)` ,
@@ -203,7 +202,7 @@ describe('ERC7739Utils', function () {
203
202
} ) ) ,
204
203
) ) {
205
204
it ( descr , async function ( ) {
206
- expect ( this . mock . $decodeContentsDescr ( contentDescr ) ) . to . eventually . deep . equal ( [
205
+ await expect ( this . mock . $decodeContentsDescr ( contentDescr ) ) . to . eventually . deep . equal ( [
207
206
contentTypeName ?? '' ,
208
207
contentTypeName ? contentType ?? contentDescr : '' ,
209
208
] ) ;
0 commit comments