-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9cc2878
commit 0770c63
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
v-next/hardhat-chai-matchers/test/multi-network-connections.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import type { EthereumProvider } from "@ignored/hardhat-vnext/types/providers"; | ||
import type { | ||
HardhatEthers, | ||
HardhatEthersSigner, | ||
} from "@ignored/hardhat-vnext-ethers/types"; | ||
|
||
import assert from "node:assert/strict"; | ||
import { before, beforeEach, describe, it } from "node:test"; | ||
|
||
import { createHardhatRuntimeEnvironment } from "@ignored/hardhat-vnext/hre"; | ||
import hardhatEthersPlugin from "@ignored/hardhat-vnext-ethers"; | ||
import { expect } from "chai"; | ||
|
||
import { addChaiMatchers } from "../src/internal/add-chai-matchers.js"; | ||
|
||
addChaiMatchers(); | ||
|
||
describe("handle multiple connections", () => { | ||
let sender: HardhatEthersSigner; | ||
let receiver: HardhatEthersSigner; | ||
|
||
let sender2: HardhatEthersSigner; | ||
let receiver2: HardhatEthersSigner; | ||
|
||
let provider: EthereumProvider; | ||
let ethers: HardhatEthers; | ||
|
||
let provider2: EthereumProvider; | ||
let ethers2: HardhatEthers; | ||
|
||
before(async () => { | ||
const hre = await createHardhatRuntimeEnvironment({ | ||
plugins: [hardhatEthersPlugin], | ||
networks: { | ||
test1: { | ||
type: "edr", | ||
chainId: 1, | ||
}, | ||
test2: { | ||
type: "edr", | ||
chainId: 2, | ||
}, | ||
}, | ||
}); | ||
|
||
({ ethers, provider } = await hre.network.connect("test1")); | ||
|
||
({ ethers: ethers2, provider: provider2 } = | ||
await hre.network.connect("test2")); | ||
}); | ||
|
||
beforeEach(async () => { | ||
const wallets = await ethers.getSigners(); | ||
sender = wallets[0]; | ||
receiver = wallets[1]; | ||
|
||
const wallets2 = await ethers2.getSigners(); | ||
sender2 = wallets2[0]; | ||
receiver2 = wallets2[1]; | ||
}); | ||
|
||
describe("it should handle 2 separate connections", () => { | ||
it("should modify the balance only in the first connection, not te second one", async () => { | ||
// Be sure that the addresses in the 2 networks are the same | ||
assert.equal(sender.address, sender2.address); | ||
assert.equal(receiver.address, receiver2.address); | ||
|
||
// Send a transaction from the first connection | ||
let nonceSender = await sender.getNonce(); | ||
let nonceSender2 = await sender2.getNonce(); | ||
|
||
await expect(() => | ||
sender.sendTransaction({ | ||
to: receiver.address, | ||
value: 200, | ||
}), | ||
).to.changeEtherBalance(provider, sender, "-200"); | ||
|
||
// Only the sender nonce should be changed | ||
assert.equal(await sender.getNonce(), nonceSender + 1); | ||
assert.equal(await sender2.getNonce(), nonceSender2); | ||
|
||
// Send a transaction from the second connection | ||
nonceSender = await sender.getNonce(); | ||
nonceSender2 = await sender2.getNonce(); | ||
|
||
await expect(() => | ||
sender2.sendTransaction({ | ||
to: receiver2.address, | ||
value: 200, | ||
}), | ||
).to.changeEtherBalance(provider2, sender2, "-200"); | ||
|
||
// Only the sender2 nonce should be changed | ||
assert.equal(await sender.getNonce(), nonceSender); | ||
assert.equal(await sender2.getNonce(), nonceSender2 + 1); | ||
}); | ||
}); | ||
}); |