Skip to content

Commit

Permalink
Fix hardhat-ethers tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fvictorio committed Mar 31, 2021
1 parent f839c16 commit da3d99f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class FakeTransaction extends Transaction {
nonce: new BN(nonce),
gasPrice: new BN(gasPrice),
gasLimit: new BN(gasLimit),
to: to !== undefined ? new Address(to) : undefined,
to: to !== undefined && to.length > 0 ? new Address(to) : undefined,
value: new BN(value),
data: data ?? emptyBuffer,
v: v !== undefined && !v.equals(emptyBuffer) ? new BN(v) : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { EMPTY_ACCOUNT_ADDRESS } from "../../helpers/constants";
import { quantityToNumber } from "../../helpers/conversions";
import { setCWD } from "../../helpers/cwd";
import { DEFAULT_ACCOUNTS_ADDRESSES, PROVIDERS } from "../../helpers/providers";
import { deployContract } from "../../helpers/transactions";

describe("Hardhat module", function () {
PROVIDERS.forEach(({ name, useProvider, isFork }) => {
Expand Down Expand Up @@ -46,6 +47,54 @@ describe("Hardhat module", function () {
);
assert.isTrue(result);
});

it("lets you send a transaction from an impersonated account", async function () {
const impersonatedAddress =
"0xC014BA5EC014ba5ec014Ba5EC014ba5Ec014bA5E";

await this.provider.send("eth_sendTransaction", [
{
from: DEFAULT_ACCOUNTS_ADDRESSES[0],
to: impersonatedAddress,
value: "0x100",
},
]);

await this.provider.send("hardhat_impersonateAccount", [
impersonatedAddress,
]);

await this.provider.send("eth_sendTransaction", [
{
from: impersonatedAddress,
to: DEFAULT_ACCOUNTS_ADDRESSES[0],
value: "0x10",
},
]);
});

it("lets you deploy a contract from an impersonated account", async function () {
const impersonatedAddress =
"0xC014BA5EC014ba5ec014Ba5EC014ba5Ec014bA5E";

await this.provider.send("eth_sendTransaction", [
{
from: DEFAULT_ACCOUNTS_ADDRESSES[0],
to: impersonatedAddress,
value: "0x100",
},
]);

await this.provider.send("hardhat_impersonateAccount", [
impersonatedAddress,
]);

await deployContract(
this.provider,
"0x7f410000000000000000000000000000000000000000000000000000000000000060005260016000f3",
impersonatedAddress
);
});
});

describe("hardhat_stopImpersonatingAccount", function () {
Expand Down

0 comments on commit da3d99f

Please sign in to comment.