diff --git a/package-lock.json b/package-lock.json index 1df4ef13..cb5881c4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,6 @@ "license": "MPL", "dependencies": { "@openzeppelin/contracts": "^5.0.2", - "eth-sig-util": "^3.0.1", "ethereumjs-wallet": "^1.0.2" }, "devDependencies": { @@ -29,6 +28,7 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^6.0.1", "eth-gas-reporter": "^0.2.27", + "eth-sig-util": "^3.0.1", "ethereumjs-util": "^7.1.5", "ethjs-abi": "^0.2.1", "ethlint": "^1.2.5", @@ -58,9 +58,9 @@ } }, "node_modules/@adraffy/ens-normalize": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/@adraffy/ens-normalize/-/ens-normalize-1.10.0.tgz", - "integrity": "sha512-nA9XHtlAkYfJxY7bce8DcN7eKxWWCWkU+1GR9d+U6MbNpfwQp8TI7vqOsBsMcHoT4mBu2kypKoSKnghEzOOq5Q==", + "version": "1.9.2", + "resolved": "https://registry.npmjs.org/@adraffy/ens-normalize/-/ens-normalize-1.9.2.tgz", + "integrity": "sha512-0h+FrQDqe2Wn+IIGFkTCd4aAwTJ+7834Ek1COohCyV26AXhwQ7WQaz+4F/nLOeVl/3BtWHOHLPsq46V8YB46Eg==", "dev": true, "peer": true }, @@ -3582,32 +3582,6 @@ "dev": true, "optional": true }, - "node_modules/@noble/curves": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.2.0.tgz", - "integrity": "sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==", - "dev": true, - "peer": true, - "dependencies": { - "@noble/hashes": "1.3.2" - }, - "funding": { - "url": "https://paulmillr.com/funding/" - } - }, - "node_modules/@noble/curves/node_modules/@noble/hashes": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.2.tgz", - "integrity": "sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==", - "dev": true, - "peer": true, - "engines": { - "node": ">= 16" - }, - "funding": { - "url": "https://paulmillr.com/funding/" - } - }, "node_modules/@noble/hashes": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.2.0.tgz", @@ -9814,6 +9788,7 @@ "resolved": "https://registry.npmjs.org/eth-sig-util/-/eth-sig-util-3.0.1.tgz", "integrity": "sha512-0Us50HiGGvZgjtWTyAI/+qTzYPMLy5Q451D0Xy68bxq1QMWdoOddDwGvsqcFT27uohKgalM9z/yxplyt+mY2iQ==", "deprecated": "Deprecated in favor of '@metamask/eth-sig-util'", + "dev": true, "dependencies": { "ethereumjs-abi": "^0.6.8", "ethereumjs-util": "^5.1.1", @@ -9825,6 +9800,7 @@ "version": "0.1.3", "resolved": "https://registry.npmjs.org/ethereum-cryptography/-/ethereum-cryptography-0.1.3.tgz", "integrity": "sha512-w8/4x1SGGzc+tO97TASLja6SLd3fRIK2tLVcV2Gx4IB21hE19atll5Cq9o3d0ZmAYC/8aw0ipieTSiekAea4SQ==", + "dev": true, "dependencies": { "@types/pbkdf2": "^3.0.0", "@types/secp256k1": "^4.0.1", @@ -9847,6 +9823,7 @@ "version": "5.2.1", "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-5.2.1.tgz", "integrity": "sha512-v3kT+7zdyCm1HIqWlLNrHGqHGLpGYIhjeHxQjnDXjLT2FyGJDsd3LWMYUo7pAFRrk86CR3nUJfhC81CCoJNNGQ==", + "dev": true, "dependencies": { "bn.js": "^4.11.0", "create-hash": "^1.1.2", @@ -9882,6 +9859,7 @@ "version": "0.6.8", "resolved": "https://registry.npmjs.org/ethereumjs-abi/-/ethereumjs-abi-0.6.8.tgz", "integrity": "sha512-Tx0r/iXI6r+lRsdvkFDlut0N08jWMnKRZ6Gkq+Nmw75lZe4e6o3EkSnkaBP5NF6+m5PTGAr9JP43N3LyeoglsA==", + "dev": true, "dependencies": { "bn.js": "^4.11.8", "ethereumjs-util": "^6.0.0" @@ -9891,6 +9869,7 @@ "version": "4.11.6", "resolved": "https://registry.npmjs.org/@types/bn.js/-/bn.js-4.11.6.tgz", "integrity": "sha512-pqr857jrp2kPuO9uRjZ3PwnJTjoQy+fcdxvBTvHm6dkmEL9q+hDD/2j/0ELOBPtPnS8LjCX0gI9nbl8lVkadpg==", + "dev": true, "dependencies": { "@types/node": "*" } @@ -9899,6 +9878,7 @@ "version": "0.1.3", "resolved": "https://registry.npmjs.org/ethereum-cryptography/-/ethereum-cryptography-0.1.3.tgz", "integrity": "sha512-w8/4x1SGGzc+tO97TASLja6SLd3fRIK2tLVcV2Gx4IB21hE19atll5Cq9o3d0ZmAYC/8aw0ipieTSiekAea4SQ==", + "dev": true, "dependencies": { "@types/pbkdf2": "^3.0.0", "@types/secp256k1": "^4.0.1", @@ -9921,6 +9901,7 @@ "version": "6.2.1", "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-6.2.1.tgz", "integrity": "sha512-W2Ktez4L01Vexijrm5EB6w7dg4n/TgpoYU4avuT5T3Vmnw/eCRtiBrJfQYS/DCSvDIOLn2k57GcHdeBcgVxAqw==", + "dev": true, "dependencies": { "@types/bn.js": "^4.11.3", "bn.js": "^4.11.0", @@ -10011,9 +9992,9 @@ } }, "node_modules/ethers": { - "version": "6.9.0", - "resolved": "https://registry.npmjs.org/ethers/-/ethers-6.9.0.tgz", - "integrity": "sha512-pmfNyQzc2mseLe91FnT2vmNaTt8dDzhxZ/xItAV7uGsF4dI4ek2ufMu3rAkgQETL/TIs0GS5A+U05g9QyWnv3Q==", + "version": "6.7.1", + "resolved": "https://registry.npmjs.org/ethers/-/ethers-6.7.1.tgz", + "integrity": "sha512-qX5kxIFMfg1i+epfgb0xF4WM7IqapIIu50pOJ17aebkxxa4BacW5jFrQRmCJpDEg2ZK2oNtR5QjrQ1WDBF29dA==", "dev": true, "funding": [ { @@ -10027,9 +10008,9 @@ ], "peer": true, "dependencies": { - "@adraffy/ens-normalize": "1.10.0", - "@noble/curves": "1.2.0", - "@noble/hashes": "1.3.2", + "@adraffy/ens-normalize": "1.9.2", + "@noble/hashes": "1.1.2", + "@noble/secp256k1": "1.7.1", "@types/node": "18.15.13", "aes-js": "4.0.0-beta.5", "tslib": "2.4.0", @@ -10040,17 +10021,17 @@ } }, "node_modules/ethers/node_modules/@noble/hashes": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.2.tgz", - "integrity": "sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.1.2.tgz", + "integrity": "sha512-KYRCASVTv6aeUi1tsF8/vpyR7zpfs3FUzy2Jqm+MU+LmUKhQ0y2FpfwqkCcxSg2ua4GALJd8k2R76WxwZGbQpA==", "dev": true, - "peer": true, - "engines": { - "node": ">= 16" - }, - "funding": { - "url": "https://paulmillr.com/funding/" - } + "funding": [ + { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + ], + "peer": true }, "node_modules/ethers/node_modules/@types/node": { "version": "18.15.13", @@ -10124,6 +10105,7 @@ "version": "0.1.6", "resolved": "https://registry.npmjs.org/ethjs-util/-/ethjs-util-0.1.6.tgz", "integrity": "sha512-CUnVOQq7gSpDHZVVrQW8ExxUETWrnrvXYvYz55wOU8Uj4VCgw56XC2B/fVqQN+f7gmrnRHSLVnFAwsCuNwji8w==", + "dev": true, "dependencies": { "is-hex-prefixed": "1.0.0", "strip-hex-prefix": "1.0.0" @@ -12886,6 +12868,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-hex-prefixed/-/is-hex-prefixed-1.0.0.tgz", "integrity": "sha512-WvtOiug1VFrE9v1Cydwm+FnXd3+w9GaeVUss5W4v/SLy3UW00vP+6iNF2SdnfiBoLy4bTqVdkftNGTUeOFVsbA==", + "dev": true, "engines": { "node": ">=6.5.0", "npm": ">=3" @@ -21578,6 +21561,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/strip-hex-prefix/-/strip-hex-prefix-1.0.0.tgz", "integrity": "sha512-q8d4ue7JGEiVcypji1bALTos+0pWtyGlivAWyPuTkHzuTCJqrK9sWxYQZUq6Nq3cuyv3bm734IhHvHtGGURU6A==", + "dev": true, "dependencies": { "is-hex-prefixed": "1.0.0" }, @@ -22218,12 +22202,14 @@ "node_modules/tweetnacl": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", - "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==", + "dev": true }, "node_modules/tweetnacl-util": { "version": "0.15.1", "resolved": "https://registry.npmjs.org/tweetnacl-util/-/tweetnacl-util-0.15.1.tgz", - "integrity": "sha512-RKJBIj8lySrShN4w6i/BonWp2Z/uxwC3h4y7xsRrpP59ZboCd0GpEVsOnMDYLMmKBpYhb5TgHzZXy7wTfYFBRw==" + "integrity": "sha512-RKJBIj8lySrShN4w6i/BonWp2Z/uxwC3h4y7xsRrpP59ZboCd0GpEVsOnMDYLMmKBpYhb5TgHzZXy7wTfYFBRw==", + "dev": true }, "node_modules/type": { "version": "1.2.0", @@ -23707,9 +23693,9 @@ "dev": true }, "@adraffy/ens-normalize": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/@adraffy/ens-normalize/-/ens-normalize-1.10.0.tgz", - "integrity": "sha512-nA9XHtlAkYfJxY7bce8DcN7eKxWWCWkU+1GR9d+U6MbNpfwQp8TI7vqOsBsMcHoT4mBu2kypKoSKnghEzOOq5Q==", + "version": "1.9.2", + "resolved": "https://registry.npmjs.org/@adraffy/ens-normalize/-/ens-normalize-1.9.2.tgz", + "integrity": "sha512-0h+FrQDqe2Wn+IIGFkTCd4aAwTJ+7834Ek1COohCyV26AXhwQ7WQaz+4F/nLOeVl/3BtWHOHLPsq46V8YB46Eg==", "dev": true, "peer": true }, @@ -26211,25 +26197,6 @@ "dev": true, "optional": true }, - "@noble/curves": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.2.0.tgz", - "integrity": "sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==", - "dev": true, - "peer": true, - "requires": { - "@noble/hashes": "1.3.2" - }, - "dependencies": { - "@noble/hashes": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.2.tgz", - "integrity": "sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==", - "dev": true, - "peer": true - } - } - }, "@noble/hashes": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.2.0.tgz", @@ -31065,6 +31032,7 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/eth-sig-util/-/eth-sig-util-3.0.1.tgz", "integrity": "sha512-0Us50HiGGvZgjtWTyAI/+qTzYPMLy5Q451D0Xy68bxq1QMWdoOddDwGvsqcFT27uohKgalM9z/yxplyt+mY2iQ==", + "dev": true, "requires": { "ethereumjs-abi": "^0.6.8", "ethereumjs-util": "^5.1.1", @@ -31076,6 +31044,7 @@ "version": "0.1.3", "resolved": "https://registry.npmjs.org/ethereum-cryptography/-/ethereum-cryptography-0.1.3.tgz", "integrity": "sha512-w8/4x1SGGzc+tO97TASLja6SLd3fRIK2tLVcV2Gx4IB21hE19atll5Cq9o3d0ZmAYC/8aw0ipieTSiekAea4SQ==", + "dev": true, "requires": { "@types/pbkdf2": "^3.0.0", "@types/secp256k1": "^4.0.1", @@ -31098,6 +31067,7 @@ "version": "5.2.1", "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-5.2.1.tgz", "integrity": "sha512-v3kT+7zdyCm1HIqWlLNrHGqHGLpGYIhjeHxQjnDXjLT2FyGJDsd3LWMYUo7pAFRrk86CR3nUJfhC81CCoJNNGQ==", + "dev": true, "requires": { "bn.js": "^4.11.0", "create-hash": "^1.1.2", @@ -31135,6 +31105,7 @@ "version": "0.6.8", "resolved": "https://registry.npmjs.org/ethereumjs-abi/-/ethereumjs-abi-0.6.8.tgz", "integrity": "sha512-Tx0r/iXI6r+lRsdvkFDlut0N08jWMnKRZ6Gkq+Nmw75lZe4e6o3EkSnkaBP5NF6+m5PTGAr9JP43N3LyeoglsA==", + "dev": true, "requires": { "bn.js": "^4.11.8", "ethereumjs-util": "^6.0.0" @@ -31144,6 +31115,7 @@ "version": "4.11.6", "resolved": "https://registry.npmjs.org/@types/bn.js/-/bn.js-4.11.6.tgz", "integrity": "sha512-pqr857jrp2kPuO9uRjZ3PwnJTjoQy+fcdxvBTvHm6dkmEL9q+hDD/2j/0ELOBPtPnS8LjCX0gI9nbl8lVkadpg==", + "dev": true, "requires": { "@types/node": "*" } @@ -31152,6 +31124,7 @@ "version": "0.1.3", "resolved": "https://registry.npmjs.org/ethereum-cryptography/-/ethereum-cryptography-0.1.3.tgz", "integrity": "sha512-w8/4x1SGGzc+tO97TASLja6SLd3fRIK2tLVcV2Gx4IB21hE19atll5Cq9o3d0ZmAYC/8aw0ipieTSiekAea4SQ==", + "dev": true, "requires": { "@types/pbkdf2": "^3.0.0", "@types/secp256k1": "^4.0.1", @@ -31174,6 +31147,7 @@ "version": "6.2.1", "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-6.2.1.tgz", "integrity": "sha512-W2Ktez4L01Vexijrm5EB6w7dg4n/TgpoYU4avuT5T3Vmnw/eCRtiBrJfQYS/DCSvDIOLn2k57GcHdeBcgVxAqw==", + "dev": true, "requires": { "@types/bn.js": "^4.11.3", "bn.js": "^4.11.0", @@ -31267,15 +31241,15 @@ } }, "ethers": { - "version": "6.9.0", - "resolved": "https://registry.npmjs.org/ethers/-/ethers-6.9.0.tgz", - "integrity": "sha512-pmfNyQzc2mseLe91FnT2vmNaTt8dDzhxZ/xItAV7uGsF4dI4ek2ufMu3rAkgQETL/TIs0GS5A+U05g9QyWnv3Q==", + "version": "6.7.1", + "resolved": "https://registry.npmjs.org/ethers/-/ethers-6.7.1.tgz", + "integrity": "sha512-qX5kxIFMfg1i+epfgb0xF4WM7IqapIIu50pOJ17aebkxxa4BacW5jFrQRmCJpDEg2ZK2oNtR5QjrQ1WDBF29dA==", "dev": true, "peer": true, "requires": { - "@adraffy/ens-normalize": "1.10.0", - "@noble/curves": "1.2.0", - "@noble/hashes": "1.3.2", + "@adraffy/ens-normalize": "1.9.2", + "@noble/hashes": "1.1.2", + "@noble/secp256k1": "1.7.1", "@types/node": "18.15.13", "aes-js": "4.0.0-beta.5", "tslib": "2.4.0", @@ -31283,9 +31257,9 @@ }, "dependencies": { "@noble/hashes": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.2.tgz", - "integrity": "sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.1.2.tgz", + "integrity": "sha512-KYRCASVTv6aeUi1tsF8/vpyR7zpfs3FUzy2Jqm+MU+LmUKhQ0y2FpfwqkCcxSg2ua4GALJd8k2R76WxwZGbQpA==", "dev": true, "peer": true }, @@ -31359,6 +31333,7 @@ "version": "0.1.6", "resolved": "https://registry.npmjs.org/ethjs-util/-/ethjs-util-0.1.6.tgz", "integrity": "sha512-CUnVOQq7gSpDHZVVrQW8ExxUETWrnrvXYvYz55wOU8Uj4VCgw56XC2B/fVqQN+f7gmrnRHSLVnFAwsCuNwji8w==", + "dev": true, "requires": { "is-hex-prefixed": "1.0.0", "strip-hex-prefix": "1.0.0" @@ -33486,7 +33461,8 @@ "is-hex-prefixed": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-hex-prefixed/-/is-hex-prefixed-1.0.0.tgz", - "integrity": "sha512-WvtOiug1VFrE9v1Cydwm+FnXd3+w9GaeVUss5W4v/SLy3UW00vP+6iNF2SdnfiBoLy4bTqVdkftNGTUeOFVsbA==" + "integrity": "sha512-WvtOiug1VFrE9v1Cydwm+FnXd3+w9GaeVUss5W4v/SLy3UW00vP+6iNF2SdnfiBoLy4bTqVdkftNGTUeOFVsbA==", + "dev": true }, "is-lower-case": { "version": "1.1.3", @@ -39957,6 +39933,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/strip-hex-prefix/-/strip-hex-prefix-1.0.0.tgz", "integrity": "sha512-q8d4ue7JGEiVcypji1bALTos+0pWtyGlivAWyPuTkHzuTCJqrK9sWxYQZUq6Nq3cuyv3bm734IhHvHtGGURU6A==", + "dev": true, "requires": { "is-hex-prefixed": "1.0.0" } @@ -40470,12 +40447,14 @@ "tweetnacl": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", - "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==", + "dev": true }, "tweetnacl-util": { "version": "0.15.1", "resolved": "https://registry.npmjs.org/tweetnacl-util/-/tweetnacl-util-0.15.1.tgz", - "integrity": "sha512-RKJBIj8lySrShN4w6i/BonWp2Z/uxwC3h4y7xsRrpP59ZboCd0GpEVsOnMDYLMmKBpYhb5TgHzZXy7wTfYFBRw==" + "integrity": "sha512-RKJBIj8lySrShN4w6i/BonWp2Z/uxwC3h4y7xsRrpP59ZboCd0GpEVsOnMDYLMmKBpYhb5TgHzZXy7wTfYFBRw==", + "dev": true }, "type": { "version": "1.2.0", diff --git a/package.json b/package.json index ef9e59f0..6c6d6bcf 100644 --- a/package.json +++ b/package.json @@ -77,6 +77,7 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^6.0.1", "eth-gas-reporter": "^0.2.27", + "eth-sig-util": "^3.0.1", "ethereumjs-util": "^7.1.5", "ethjs-abi": "^0.2.1", "ethlint": "^1.2.5", @@ -97,7 +98,6 @@ }, "dependencies": { "@openzeppelin/contracts": "^5.0.2", - "eth-sig-util": "^3.0.1", "ethereumjs-wallet": "^1.0.2" } } diff --git a/test/common/MetaTxModuleCommon.js b/test/common/MetaTxModuleCommon.js new file mode 100644 index 00000000..5ab814b6 --- /dev/null +++ b/test/common/MetaTxModuleCommon.js @@ -0,0 +1,80 @@ +const helpers = require('@nomicfoundation/hardhat-network-helpers'); +const { + getDomain, + ForwardRequest, +} = require('../../openzeppelin-contracts-upgradeable/test/helpers/eip712') +const { expect } = require('chai') +const { waffle} = require("hardhat"); +function MetaTxModuleCommon () { + context('Transferring without paying gas', function () { + const AMOUNT_TO_TRANSFER = 11n + const ADDRESS1_INITIAL_BALANCE = 31n + const ADDRESS2_INITIAL_BALANCE = 32n + + beforeEach(async function () { + // From https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/test/metatx/ERC2771Forwarder.test.js + this.domain = await getDomain(this.forwarder) + this.types = { + ForwardRequest: [ + { name: 'from', type: 'address' }, + { name: 'to', type: 'address' }, + { name: 'value', type: 'uint256' }, + { name: 'gas', type: 'uint256' }, + { name: 'nonce', type: 'uint256' }, + { name: 'deadline', type: 'uint48' }, + { name: 'data', type: 'bytes' } + ] + } + await this.cmtat.connect(this.admin).mint(this.address1, ADDRESS1_INITIAL_BALANCE) + await this.cmtat.connect(this.admin).mint(this.address2, ADDRESS2_INITIAL_BALANCE); + expect(await this.cmtat.balanceOf(this.address1)).to.equal( + ADDRESS1_INITIAL_BALANCE + ) + this.data = this.cmtat.interface.encodeFunctionData('transfer',[this.address2.address, AMOUNT_TO_TRANSFER]) + this.forgeRequest = async (override = {}, signer = this.address1) => { + const req = { + from: await signer.getAddress(), + to: this.cmtat.target, + value: 0n, + data: this.data, + gas: 100000n, + deadline: (await helpers.time.latest()) + 60, + nonce: await this.forwarder.nonces(this.address1), + ...override, + }; + req.signature = await signer.signTypedData(this.domain, this.types, req); + return req; + }; + }) + + it('returns true without altering the nonce', async function () { + const request = await this.forgeRequest(); + expect( + await this.forwarder.nonces(request.from) + ).to.equal(request.nonce) + expect(await this.forwarder.verify(request)).to.be.equal(true) + expect( + await this.forwarder.nonces(request.from) + ).to.equal(request.nonce) + }) + + it('can send a transfer transaction without paying gas', async function () { + const provider = await ethers.getDefaultProvider();; + const balanceEtherBefore = await provider.getBalance(this.address1); + expect(await this.cmtat.balanceOf(this.address1)).to.equal( + ADDRESS1_INITIAL_BALANCE + ) + const request = await this.forgeRequest(); + await this.forwarder.connect(this.address3).execute(request); + expect(await this.cmtat.balanceOf(this.address1)).to.equal( + ADDRESS1_INITIAL_BALANCE - AMOUNT_TO_TRANSFER + ); + expect(await this.cmtat.balanceOf(this.address2)).to.equal( + ADDRESS2_INITIAL_BALANCE + AMOUNT_TO_TRANSFER + ) + const balanceAfter = await provider.getBalance(this.address1) + expect(balanceEtherBefore).to.equal(balanceAfter) + }) + }) +} +module.exports = MetaTxModuleCommon diff --git a/test/common/MetaTxModuleCommonOld b/test/common/MetaTxModuleCommonOld deleted file mode 100644 index 3e6f3e72..00000000 --- a/test/common/MetaTxModuleCommonOld +++ /dev/null @@ -1,145 +0,0 @@ -const helpers = require('@nomicfoundation/hardhat-network-helpers'); -const { - getDomain, - domainType, - ForwardRequest, -} = require('../../openzeppelin-contracts-upgradeable/test/helpers/eip712') -/*const { - time -} = require('../../openzeppelin-contracts-upgradeable/test/helpers/time')*/ -const { expect } = require('chai') -const { waffle} = require("hardhat"); -function MetaTxModuleCommon (owner, address1) { - context('Transferring without paying gas', function () { - const AMOUNT_TO_TRANSFER = 11n - const ADDRESS1_INITIAL_BALANCE = 31n - const ADDRESS2_INITIAL_BALANCE = 32n - - beforeEach(async function () { - //this.aliceWallet = ethers.Wallet.createRandom() - //this.address1 = this.aliceWallet.address - - this.domain = await getDomain(this.forwarder) - /*ForwardRequest = { - from: 'address', - to: 'address', - value: 'uint256', - gas: 'uint256', - nonce: 'uint256', - deadline: 'uint48', - data: 'bytes', - };*/ - //this.types = { ForwardRequest }; - //this.types = { ForwardRequest }; - /*this.types = { - EIP712Domain: domainType(this.domain), - ForwardRequest: [ - { name: 'from', type: 'address' }, - { name: 'to', type: 'address' }, - { name: 'value', type: 'uint256' }, - { name: 'gas', type: 'uint256' }, - { name: 'nonce', type: 'uint256' }, - { name: 'deadline', type: 'uint48' }, - { name: 'data', type: 'bytes' } - ] - }*/ - this.types = { - ForwardRequest: [ - { name: 'from', type: 'address' }, - { name: 'to', type: 'address' }, - { name: 'value', type: 'uint256' }, - { name: 'gas', type: 'uint256' }, - { name: 'nonce', type: 'uint256' }, - { name: 'deadline', type: 'uint48' }, - { name: 'data', type: 'bytes' } - ] - } - await this.cmtat.connect(this.admin).mint(this.address1, ADDRESS1_INITIAL_BALANCE) - await this.cmtat.connect(this.admin).mint(this.address2, ADDRESS2_INITIAL_BALANCE); - expect(await this.cmtat.balanceOf(this.address1)).to.equal( - ADDRESS1_INITIAL_BALANCE - ) - //this.timestamp = await time.latest() - /*const data = this.cmtat.ADDRESS2_INITIAL_BALANCE - .transfer(address1, AMOUNT_TO_TRANSFER) - .encodeABI()*/ - this.data = this.cmtat.transfer.populateTransaction(this.address2, AMOUNT_TO_TRANSFER).data - this.request = { - from: this.address1.address, - to: this.cmtat.address, - value: 0n, - gas: 100000n, - data:this.data, - deadline: this.timestamp + 180, - nonce: (await this.forwarder.nonces(this.address1)), - ...{}// 3 minute - } - /*this.requestData = { - ...this.request, - nonce: (await this.forwarder.nonces(this.address1)).toString() - }*/ - - /*this.forgeData = (request) => ({ - types: this.types, - domain: this.domain, - primaryType: 'ForwardRequest', - message: { ...this.requestData, ...request } - - })*/ - //const [sender, refundReceiver, another, ...accounts] = await ethers.getSigners(); - - - /*this.sign = (privateKey, request) => - ethSigUtil.signTypedMessage(privateKey, { - data: this.forgeData(request) - })*/ - - //this.requestData.signature = this.sign(this.aliceWallet.getPrivateKey()) - this.forgeRequest = async (override = {}, signer = this.address1) => { - const req = { - from: await signer.getAddress(), - to: this.cmtat.address, - value: 0n, - data: this.data, - gas: 100000n, - deadline: (await helpers.time.latest()) + 60, - nonce: await this.forwarder.nonces(this.address1), - ...override, - }; - //req.signature = await signer.signTypedData(this.domain, this.types, req); - return req; - }; - }) - - it('returns true without altering the nonce', async function () { - /*expect( - await this.forwarder.nonces(this.requestData.from) - ).to.equal(web3.utils.toBN(this.requestData.nonce)) - expect(await this.forwarder.verify(this.requestData)).to.be.equal(true) - expect( - await this.forwarder.nonces(this.requestData.from) - ).to.equal(web3.utils.toBN(this.requestData.nonce))*/ - }) - - it('can send a transfer transaction without paying gas', async function () { - // TODO : code for the new version of the library, it doesn't compile - // const sign = ethSigUtil.signTypedData( {privateKey : this.wallet.getPrivateKey(), data: { ...this.data, message: req }, version : 'V4'}); - const provider = await ethers.getDefaultProvider();; - const balanceEtherBefore = await provider.getBalance(this.address1); - expect(await this.cmtat.balanceOf(this.address1)).to.equal( - ADDRESS1_INITIAL_BALANCE - ) - const request = await this.forgeRequest(); - //await this.forwarder.execute(request); - /*expect(await this.cmtat.balanceOf(this.address1)).to.equal( - ADDRESS1_INITIAL_BALANCE - AMOUNT_TO_TRANSFER - ); - expect(await this.cmtat.balanceOf(this.address2)).to.equal( - ADDRESS2_INITIAL_BALANCE + AMOUNT_TO_TRANSFER - ) - const balanceAfter = await ethers.getBalance(this.address1) - expect(balanceEtherBefore).to.equal(balanceAfter)*/ - }) - }) -} -module.exports = MetaTxModuleCommon diff --git a/test/proxy/general/UpgradeProxy.test.js b/test/proxy/general/UpgradeProxy.test.js index 47243781..699a82f7 100644 --- a/test/proxy/general/UpgradeProxy.test.js +++ b/test/proxy/general/UpgradeProxy.test.js @@ -91,20 +91,19 @@ describe( ) // Just to be sure that the proxy address remains unchanged - expect(ETHER_PROXY_ADDRESS).to.equal(PROXY_ADDRESS_V2_INSTANCE) + expect(ETHER_PROXY_ADDRESS).to.equal(PROXY_ADDRESS_V2_INSTANCE); // The address of the implementation contract has changed - expect(IMPLEMENTATION_CONTRACT_ADDRESS_V1).not.to.be.equal( + expect(IMPLEMENTATION_CONTRACT_ADDRESS_V1).to.not.equal( IMPLEMENTATION_CONTRACT_ADDRESS_V2 - )( + ); // Just to be sure that the proxy address remains unchanged // TRUFFLE_CMTAT_PROXY_ADDRESS.to.equal(TRUFFLE_CMTAT_PROXY_ADDRESS_2); - ({ logs: this.logs1 } = await ETHERS_CMTAT_PROXY_V2.balanceOf( - this.address1 - )) - ); + ({ logs: this.logs1 } = await ETHERS_CMTAT_PROXY_V2.balanceOf( + this.address1 + )) expect( await ETHERS_CMTAT_PROXY_V2.balanceOf(this.address1) @@ -118,10 +117,10 @@ describe( 20 )); expect( - await TRUFFLE_CMTAT_PROXY_ADDRESS_2.balanceOf(this.address1) + await ETHERS_CMTAT_PROXY_V2.balanceOf(this.address1) ).to.equal('40'); expect( - await TRUFFLE_CMTAT_PROXY_ADDRESS_2.totalSupply() + await ETHERS_CMTAT_PROXY_V2.totalSupply() ).to.equal('40') }) } diff --git a/test/proxy/modules/MetaTxModuleOld b/test/proxy/modules/MetaTxModule.test.js similarity index 89% rename from test/proxy/modules/MetaTxModuleOld rename to test/proxy/modules/MetaTxModule.test.js index 17c79a97..4de729ef 100644 --- a/test/proxy/modules/MetaTxModuleOld +++ b/test/proxy/modules/MetaTxModule.test.js @@ -1,4 +1,4 @@ -const MetaTxModuleCommon = require('../../common/MetaTxModuleCommonOld') +const MetaTxModuleCommon = require('../../common/MetaTxModuleCommon') const { deployCMTATProxyWithParameter, fixture, loadFixture } = require('../../deploymentUtils.js') const { ZERO_ADDRESS, ERC2771ForwarderDomain } = require('../../utils.js') @@ -12,9 +12,9 @@ describe( this.forwarder = await ethers.deployContract("MinimalForwarderMock") await this.forwarder.initialize(ERC2771ForwarderDomain) this.cmtat = await deployCMTATProxyWithParameter( - this.deployerAddress, - this.forwarder.address, - this.admin, + this.deployerAddress.address, + this.forwarder.target, + this.admin.address, ZERO_ADDRESS, 'CMTA Token', 'CMTAT', diff --git a/test/standard/modules/MetaTxModuleOld b/test/standard/modules/MetaTxModule.test.js similarity index 89% rename from test/standard/modules/MetaTxModuleOld rename to test/standard/modules/MetaTxModule.test.js index be6f92aa..41d7a7a4 100644 --- a/test/standard/modules/MetaTxModuleOld +++ b/test/standard/modules/MetaTxModule.test.js @@ -1,4 +1,4 @@ -const MetaTxModuleCommon = require('../../common/MetaTxModuleCommonOld') +const MetaTxModuleCommon = require('../../common/MetaTxModuleCommon') const { deployCMTATStandaloneWithParameter, fixture, loadFixture } = require('../../deploymentUtils.js') const { ZERO_ADDRESS, ERC2771ForwarderDomain } = require('../../utils.js') describe( @@ -12,9 +12,9 @@ describe( this.forwarder = await ethers.deployContract("MinimalForwarderMock") await this.forwarder.initialize(ERC2771ForwarderDomain) this.cmtat = await deployCMTATStandaloneWithParameter( - this.deployerAddress, - this.forwarder, - this.admin, + this.deployerAddress.address, + this.forwarder.target, + this.admin.address, ZERO_ADDRESS, 'CMTA Token', 'CMTAT',