generated from evan-gray/multichain-template
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
9 changed files
with
3,484 additions
and
305 deletions.
There are no files selected for viewing
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,49 @@ | ||
import { jest, expect, test } from "@jest/globals"; | ||
import { ethers } from "ethers"; | ||
import { | ||
claimAdmin, | ||
getAdmin, | ||
getPendingAdmin, | ||
transferAdmin, | ||
} from "../src/admin"; | ||
|
||
jest.setTimeout(180000); | ||
|
||
const fakeIntegrator = "0x1B5Ba8B47e656Afe522634ca7F058b2BE33075Af"; | ||
const nullAdmin = "0x0000000000000000000000000000000000000000"; | ||
|
||
const anvilPrivateKey = | ||
"0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d"; | ||
const anvilEthProvider = new ethers.JsonRpcProvider("http://127.0.0.1:8545"); | ||
const anvilEthSigner = new ethers.Wallet(anvilPrivateKey, anvilEthProvider); | ||
const whGuardiansAdapter = "0x8564C314028B778C968E11485E4bD6aC13CF0eeF"; | ||
|
||
describe("TS as Admin Tests", () => { | ||
// Can only be run once per Anvil deployment. | ||
|
||
describe("cancel transfer", () => { | ||
test("getAdmin, getPendingAdmin, transferAdmin, claimAdmin", async () => { | ||
const firstNonce = await anvilEthProvider.getTransactionCount( | ||
anvilEthSigner.address, | ||
); | ||
console.log("Nonce before transferAdmin:", firstNonce); | ||
|
||
await transferAdmin(whGuardiansAdapter, anvilEthSigner, fakeIntegrator); | ||
|
||
let admin = await getAdmin(whGuardiansAdapter, anvilEthSigner); | ||
let pendingAdmin = await getPendingAdmin( | ||
whGuardiansAdapter, | ||
anvilEthSigner, | ||
); | ||
expect(admin).toBe(anvilEthSigner.address); | ||
expect(pendingAdmin).toBe(fakeIntegrator); | ||
|
||
await claimAdmin(whGuardiansAdapter, anvilEthSigner); | ||
|
||
admin = await getAdmin(whGuardiansAdapter, anvilEthSigner); | ||
pendingAdmin = await getPendingAdmin(whGuardiansAdapter, anvilEthSigner); | ||
expect(admin).toBe(anvilEthSigner.address); | ||
expect(pendingAdmin).toBe(nullAdmin); | ||
}); | ||
}); | ||
}); |
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,43 @@ | ||
import { jest, expect, test } from "@jest/globals"; | ||
import { ethers } from "ethers"; | ||
import { getPeer, getPeers, setPeer } from "../src/peer"; | ||
|
||
jest.setTimeout(180000); | ||
|
||
const fakePeer = | ||
"0x0000000000000000000000001B5Ba8B47e656Afe522634ca7F058b2BE33075Af".toLowerCase(); | ||
const nullPeer = | ||
"0x0000000000000000000000000000000000000000000000000000000000000000"; | ||
|
||
const anvilPrivateKey = | ||
"0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d"; | ||
const anvilEthProvider = new ethers.JsonRpcProvider("http://127.0.0.1:8545"); | ||
const anvilEthSigner = new ethers.Wallet(anvilPrivateKey, anvilEthProvider); | ||
const anvilWhGuardiansAdapter = "0x37DFeB004c7C76C8cE4954D1659A63ACd222d2Be"; | ||
|
||
describe("setPeer", () => { | ||
test("setPeer, getPeer, getPeers", async () => { | ||
const peerChain = 1; | ||
let peer: string = await getPeer( | ||
anvilWhGuardiansAdapter, | ||
anvilEthSigner, | ||
peerChain, | ||
); | ||
console.log("peer", peer); | ||
expect(peer).toBe(nullPeer); | ||
|
||
let peers = await getPeers(anvilWhGuardiansAdapter, anvilEthSigner); | ||
console.log("peers", peers); | ||
expect(peers.length).toBe(0); | ||
|
||
await setPeer(anvilWhGuardiansAdapter, anvilEthSigner, peerChain, fakePeer); | ||
|
||
peer = await getPeer(anvilWhGuardiansAdapter, anvilEthSigner, peerChain); | ||
console.log("peer after set", peer); | ||
expect(peer).toBe(fakePeer); | ||
|
||
peers = await getPeers(anvilWhGuardiansAdapter, anvilEthSigner); | ||
console.log("peers", peers); | ||
expect(peers.length).toBe(1); | ||
}); | ||
}); |
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
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
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,35 @@ | ||
import { ethers } from "ethers"; | ||
import { | ||
WormholeGuardiansAdapter, | ||
WormholeGuardiansAdapter__factory, | ||
WormholeGuardiansAdapterWithExecutor, | ||
WormholeGuardiansAdapterWithExecutor__factory, | ||
} from "../../../abi"; | ||
|
||
export async function isExecutor( | ||
contractAddress: string, | ||
signer: ethers.Signer, | ||
): Promise<boolean> { | ||
const abiFragment = ["function executor() public view returns (address)"]; | ||
const contract = new ethers.Contract(contractAddress, abiFragment, signer); | ||
try { | ||
await contract.executor(); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
} | ||
|
||
export async function getContract( | ||
contractAddress: string, | ||
signer: ethers.Signer, | ||
): Promise<WormholeGuardiansAdapter | WormholeGuardiansAdapterWithExecutor> { | ||
if (await isExecutor(contractAddress, signer)) { | ||
return WormholeGuardiansAdapterWithExecutor__factory.connect( | ||
contractAddress, | ||
signer, | ||
); | ||
} else { | ||
return WormholeGuardiansAdapter__factory.connect(contractAddress, signer); | ||
} | ||
} |
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
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,9 @@ | ||
{ | ||
"preset": "ts-jest/presets/default-esm", | ||
"transform": { | ||
"^.+\\.tsx?$": "ts-jest" | ||
}, | ||
"testMatch": ["**/__tests__/**/*.test.ts"], | ||
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"], | ||
"testPathIgnorePatterns": ["/node_modules/", "/dist/"] | ||
} |
Oops, something went wrong.