Skip to content

Commit

Permalink
🪲 Fixing wire task to lock in default send and receive libraries (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirarthurmoney authored Feb 21, 2024
1 parent c18b99d commit ed386dc
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/fast-suits-rhyme.md
Original file line number Diff line number Diff line change
@@ -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
10 changes: 7 additions & 3 deletions packages/ua-devtools/src/oapp/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
})
)
Expand All @@ -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,
Expand Down
116 changes: 116 additions & 0 deletions tests/ua-devtools-evm-hardhat-test/test/oapp/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
avaxExecutor,
avaxReceiveUln,
avaxReceiveUln2_Opt2,
avaxSendUln,
avaxSendUln2_Opt2,
bscDvn,
bscExecutor,
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit ed386dc

Please sign in to comment.