|
| 1 | +import { ethers } from "hardhat"; |
| 2 | +import { expect } from "chai"; |
| 3 | + |
| 4 | +const REWARD_PROXY = "0x1212000000000000000000000000000000000003"; |
| 5 | +const REWARD_IMP = "0x1212100000000000000000000000000000000003"; |
| 6 | + |
| 7 | +describe("GovReward", function () { |
| 8 | + let Reward: any; |
| 9 | + let signers: any; |
| 10 | + |
| 11 | + beforeEach(async function () { |
| 12 | + // Signers |
| 13 | + signers = await ethers.getSigners(); |
| 14 | + |
| 15 | + // Reset blockchain state |
| 16 | + await ethers.provider.send("hardhat_reset") |
| 17 | + |
| 18 | + // Deploy contract |
| 19 | + const reward_deploy = await ethers.deployContract("GovReward"); |
| 20 | + |
| 21 | + // Copy Bytecode to native address |
| 22 | + const reward_code = await ethers.provider.send("eth_getCode", [reward_deploy.target]); |
| 23 | + await ethers.provider.send("hardhat_setCode", [REWARD_PROXY, reward_code]); |
| 24 | + |
| 25 | + const contract = require("../artifacts/solidity/GovReward.sol/GovReward.json"); |
| 26 | + Reward = new ethers.Contract(REWARD_PROXY, contract.abi, signers[0]); |
| 27 | + }); |
| 28 | + |
| 29 | + describe("envelope call", function () { |
| 30 | + let Mock: any; |
| 31 | + |
| 32 | + beforeEach(async function () { |
| 33 | + Mock = await ethers.deployContract("MockFallback"); |
| 34 | + }); |
| 35 | + |
| 36 | + it("Should revert if the selector is not 0xffffffff", async function () { |
| 37 | + await expect( |
| 38 | + Mock.call_fallback(REWARD_PROXY, "0xfffffffe") |
| 39 | + ).to.be.reverted; |
| 40 | + }); |
| 41 | + |
| 42 | + it("Should revert if the declared gaslimit is lower than 21000", async function () { |
| 43 | + await expect( |
| 44 | + Mock.call_fallback(REWARD_PROXY, "0xffffffff") |
| 45 | + ).to.be.reverted; |
| 46 | + }); |
| 47 | + |
| 48 | + it("Should consume gas as expected", async function () { |
| 49 | + await expect( |
| 50 | + Mock.call_fallback(REWARD_PROXY, "0xffffffff0000000000005208") |
| 51 | + ).not.to.be.reverted; |
| 52 | + }); |
| 53 | + }); |
| 54 | +}); |
0 commit comments