From ed386dc2e47378f73b3f904d3a7b902e2ee22c30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lz=2Esir=CE=94rthurmoney=28=29?= <95722332+sirarthurmoney@users.noreply.github.com> Date: Wed, 21 Feb 2024 13:44:55 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=B2=20Fixing=20wire=20task=20to=20lock?= =?UTF-8?q?=20in=20default=20send=20and=20receive=20libraries=20(#419)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/fast-suits-rhyme.md | 6 + packages/ua-devtools/src/oapp/config.ts | 10 +- .../test/oapp/config.test.ts | 116 ++++++++++++++++++ 3 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 .changeset/fast-suits-rhyme.md diff --git a/.changeset/fast-suits-rhyme.md b/.changeset/fast-suits-rhyme.md new file mode 100644 index 000000000..8fbbb87a3 --- /dev/null +++ b/.changeset/fast-suits-rhyme.md @@ -0,0 +1,6 @@ +--- +"@layerzerolabs/ua-devtools-evm-hardhat-test": patch +"@layerzerolabs/ua-devtools": patch +--- + +Fixing wire task to lock in default send and receive libraries diff --git a/packages/ua-devtools/src/oapp/config.ts b/packages/ua-devtools/src/oapp/config.ts index 0377b84fe..b0dd06d3d 100644 --- a/packages/ua-devtools/src/oapp/config.ts +++ b/packages/ua-devtools/src/oapp/config.ts @@ -55,9 +55,10 @@ export const configureSendLibraries: OAppConfigurator = async (graph, createSdk) const oappSdk = await createSdk(from) const endpointSdk = await oappSdk.getEndpointSDK() + const isDefaultLibrary = await endpointSdk.isDefaultSendLibrary(from.address, to.eid) const currentSendLibrary = await endpointSdk.getSendLibrary(from.address, to.eid) - if (currentSendLibrary === config.sendLibrary) return [] + if (!isDefaultLibrary && currentSendLibrary === config.sendLibrary) return [] return [await endpointSdk.setSendLibrary(from.address, to.eid, config.sendLibrary)] }) ) @@ -71,9 +72,12 @@ export const configureReceiveLibraries: OAppConfigurator = async (graph, createS const oappSdk = await createSdk(from) const endpointSdk = await oappSdk.getEndpointSDK() - const [currentReceiveLibrary] = await endpointSdk.getReceiveLibrary(from.address, to.eid) + const [currentReceiveLibrary, isDefaultLibrary] = await endpointSdk.getReceiveLibrary( + from.address, + to.eid + ) - if (currentReceiveLibrary === config.receiveLibraryConfig.receiveLibrary) return [] + if (!isDefaultLibrary && currentReceiveLibrary === config.receiveLibraryConfig.receiveLibrary) return [] return [ await endpointSdk.setReceiveLibrary( from.address, diff --git a/tests/ua-devtools-evm-hardhat-test/test/oapp/config.test.ts b/tests/ua-devtools-evm-hardhat-test/test/oapp/config.test.ts index 3655db3e7..d3f05e6b5 100644 --- a/tests/ua-devtools-evm-hardhat-test/test/oapp/config.test.ts +++ b/tests/ua-devtools-evm-hardhat-test/test/oapp/config.test.ts @@ -17,6 +17,7 @@ import { avaxExecutor, avaxReceiveUln, avaxReceiveUln2_Opt2, + avaxSendUln, avaxSendUln2_Opt2, bscDvn, bscExecutor, @@ -154,6 +155,56 @@ describe('oapp/config', () => { expect(errors).toEqual([]) }) + describe('configureSendLibraries lock defaults', () => { + let ethSendLibrary: string, avaxSendLibrary: string, graph: OAppOmniGraph + beforeEach(async () => { + ethSendLibrary = await getLibraryAddress(ethSendUln) + avaxSendLibrary = await getLibraryAddress(avaxSendUln) + graph = { + contracts: [ + { + point: ethPoint, + }, + { + point: avaxPoint, + }, + ], + connections: [ + { + vector: { from: ethPoint, to: avaxPoint }, + config: { + sendLibrary: ethSendLibrary, + }, + }, + { + vector: { from: avaxPoint, to: ethPoint }, + config: { + sendLibrary: avaxSendLibrary, + }, + }, + ], + } + }) + + it('should lock in default configureSendLibraries transactions', async () => { + // Now we configure the OApp + transactions = await configureOApp(graph, oappSdkFactory) + expect(transactions).toEqual([ + await ethEndpointV2Sdk.setSendLibrary(ethPoint.address, avaxPoint.eid, ethSendLibrary), + await avaxEndpointV2Sdk.setSendLibrary(avaxPoint.address, ethPoint.eid, avaxSendLibrary), + ]) + }) + + afterEach(async () => { + const [_, errors] = await signAndSend(transactions) + // eslint-disable-next-line jest/no-standalone-expect + expect(errors).toEqual([]) + const transactionsAgain = await configureOApp(graph, oappSdkFactory) + // eslint-disable-next-line jest/no-standalone-expect + expect(transactionsAgain).toEqual([]) + }) + }) + describe('configureSendLibraries', () => { let ethSendLibrary: string, avaxSendLibrary: string, graph: OAppOmniGraph beforeEach(async () => { @@ -224,6 +275,71 @@ describe('oapp/config', () => { }) }) + describe('configureReceiveLibraries lock defaults', () => { + let ethReceiveLibrary: string, avaxReceiveLibrary: string, graph: OAppOmniGraph + beforeEach(async () => { + ethReceiveLibrary = await getLibraryAddress(ethReceiveUln) + avaxReceiveLibrary = await getLibraryAddress(avaxReceiveUln) + graph = { + contracts: [ + { + point: ethPoint, + }, + { + point: avaxPoint, + }, + ], + connections: [ + { + vector: { from: ethPoint, to: avaxPoint }, + config: { + receiveLibraryConfig: { + receiveLibrary: ethReceiveLibrary, + gracePeriod: BigInt(0), + }, + }, + }, + { + vector: { from: avaxPoint, to: ethPoint }, + config: { + receiveLibraryConfig: { + receiveLibrary: avaxReceiveLibrary, + gracePeriod: BigInt(0), + }, + }, + }, + ], + } + }) + + it('should return all lock in configureReceiveLibraries transactions', async () => { + // Now we configure the OApp + transactions = await configureOApp(graph, oappSdkFactory) + expect(transactions).toEqual([ + await ethEndpointV2Sdk.setReceiveLibrary( + ethPoint.address, + avaxPoint.eid, + ethReceiveLibrary, + BigInt(0) + ), + await avaxEndpointV2Sdk.setReceiveLibrary( + avaxPoint.address, + ethPoint.eid, + avaxReceiveLibrary, + BigInt(0) + ), + ]) + }) + + afterEach(async () => { + const [_, errors] = await signAndSend(transactions) + // eslint-disable-next-line jest/no-standalone-expect + expect(errors).toEqual([]) + const transactionsAgain = await configureOApp(graph, oappSdkFactory) + // eslint-disable-next-line jest/no-standalone-expect + expect(transactionsAgain).toEqual([]) + }) + }) describe('configureReceiveLibraries', () => { let ethReceiveLibrary: string, avaxReceiveLibrary: string, graph: OAppOmniGraph beforeEach(async () => {