@ -11,7 +11,7 @@ const Wallet = require('ethereumjs-wallet').default;
const ERC20VotesComp = artifacts . require ( '$ERC20VotesComp' ) ;
const { batchInBlock } = require ( '../../../helpers/txpool' ) ;
const { EIP712Domain , domainSeparator } = require ( '../../../helpers/eip712' ) ;
const { getDomain , domainType , domainSeparator } = require ( '../../../helpers/eip712' ) ;
const { getChainId } = require ( '../../../helpers/chainid' ) ;
const Delegation = [
@ -38,9 +38,7 @@ contract('ERC20VotesComp', function (accounts) {
} ) ;
it ( 'domain separator' , async function ( ) {
expect ( await this . token . DOMAIN _SEPARATOR ( ) ) . to . equal (
await domainSeparator ( { name , version , chainId : this . chainId , verifyingContract : this . token . address } ) ,
) ;
expect ( await this . token . DOMAIN _SEPARATOR ( ) ) . to . equal ( await getDomain ( this . token ) . then ( domainSeparator ) ) ;
} ) ;
it ( 'minting restriction' , async function ( ) {
@ -94,30 +92,26 @@ contract('ERC20VotesComp', function (accounts) {
const delegatorAddress = web3 . utils . toChecksumAddress ( delegator . getAddressString ( ) ) ;
const nonce = 0 ;
const buildData = ( chainId , verifyingC ontract , message ) => ( {
data : {
const buildData = ( contract , message ) =>
getDomain ( contract ) . then ( domain => ( {
primaryType : 'Delegation' ,
types : { EIP712Domain , Delegation } ,
domain : { name , version , chainId , verifyingContract } ,
types : { EIP712Domain : domainType ( domain ) , Delegation } ,
domain ,
message ,
} ,
} ) ;
} ) ) ;
beforeEach ( async function ( ) {
await this . token . $ _mint ( delegatorAddress , supply ) ;
} ) ;
it ( 'accept signed delegation' , async function ( ) {
const { v , r , s } = fromRpcSig (
ethSigUtil . signTypedMessage (
delegator . getPrivateKey ( ) ,
buildData ( this . chainId , this . token . address , {
delegatee : delegatorAddress ,
nonce ,
expiry : MAX _UINT256 ,
} ) ,
) ,
) ;
const { v , r , s } = await buildData ( this . token , {
delegatee : delegatorAddress ,
nonce ,
expiry : MAX _UINT256 ,
} )
. then ( data => ethSigUtil . signTypedMessage ( delegator . getPrivateKey ( ) , { data } ) )
. then ( fromRpcSig ) ;
expect ( await this . token . delegates ( delegatorAddress ) ) . to . be . equal ( ZERO _ADDRESS ) ;
@ -142,16 +136,13 @@ contract('ERC20VotesComp', function (accounts) {
} ) ;
it ( 'rejects reused signature' , async function ( ) {
const { v , r , s } = fromRpcSig (
ethSigUtil . signTypedMessage (
delegator . getPrivateKey ( ) ,
buildData ( this . chainId , this . token . address , {
delegatee : delegatorAddress ,
nonce ,
expiry : MAX _UINT256 ,
} ) ,
) ,
) ;
const { v , r , s } = await buildData ( this . token , {
delegatee : delegatorAddress ,
nonce ,
expiry : MAX _UINT256 ,
} )
. then ( data => ethSigUtil . signTypedMessage ( delegator . getPrivateKey ( ) , { data } ) )
. then ( fromRpcSig ) ;
await this . token . delegateBySig ( delegatorAddress , nonce , MAX _UINT256 , v , r , s ) ;
@ -162,16 +153,13 @@ contract('ERC20VotesComp', function (accounts) {
} ) ;
it ( 'rejects bad delegatee' , async function ( ) {
const { v , r , s } = fromRpcSig (
ethSigUtil . signTypedMessage (
delegator . getPrivateKey ( ) ,
buildData ( this . chainId , this . token . address , {
delegatee : delegatorAddress ,
nonce ,
expiry : MAX _UINT256 ,
} ) ,
) ,
) ;
const { v , r , s } = await buildData ( this . token , {
delegatee : delegatorAddress ,
nonce ,
expiry : MAX _UINT256 ,
} )
. then ( data => ethSigUtil . signTypedMessage ( delegator . getPrivateKey ( ) , { data } ) )
. then ( fromRpcSig ) ;
const receipt = await this . token . delegateBySig ( holderDelegatee , nonce , MAX _UINT256 , v , r , s ) ;
const { args } = receipt . logs . find ( ( { event } ) => event == 'DelegateChanged' ) ;
@ -181,16 +169,14 @@ contract('ERC20VotesComp', function (accounts) {
} ) ;
it ( 'rejects bad nonce' , async function ( ) {
const { v , r , s } = fromRpcSig (
ethSigUtil . signTypedMessage (
delegator . getPrivateKey ( ) ,
buildData ( this . chainId , this . token . address , {
delegatee : delegatorAddress ,
nonce ,
expiry : MAX _UINT256 ,
} ) ,
) ,
) ;
const { v , r , s } = await buildData ( this . token , {
delegatee : delegatorAddress ,
nonce ,
expiry : MAX _UINT256 ,
} )
. then ( data => ethSigUtil . signTypedMessage ( delegator . getPrivateKey ( ) , { data } ) )
. then ( fromRpcSig ) ;
await expectRevert (
this . token . delegateBySig ( delegatorAddress , nonce + 1 , MAX _UINT256 , v , r , s ) ,
'ERC20Votes: invalid nonce' ,
@ -199,16 +185,14 @@ contract('ERC20VotesComp', function (accounts) {
it ( 'rejects expired permit' , async function ( ) {
const expiry = ( await time . latest ( ) ) - time . duration . weeks ( 1 ) ;
const { v , r , s } = fromRpcSig (
ethSigUtil . signTypedMessage (
delegator . getPrivateKey ( ) ,
buildData ( this . chainId , this . token . address , {
delegatee : delegatorAddress ,
nonce ,
expiry ,
} ) ,
) ,
) ;
const { v , r , s } = await buildData ( this . token , {
delegatee : delegatorAddress ,
nonce ,
expiry ,
} )
. then ( data => ethSigUtil . signTypedMessage ( delegator . getPrivateKey ( ) , { data } ) )
. then ( fromRpcSig ) ;
await expectRevert (
this . token . delegateBySig ( delegatorAddress , nonce , expiry , v , r , s ) ,