-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🪚 OmniGraph™ Adding access to Uln302 SDK to Endpoint SDK (#98)
- Loading branch information
1 parent
5fd7196
commit 2f6659a
Showing
12 changed files
with
135 additions
and
25 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
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,14 @@ | ||
import pMemoize from 'p-memoize' | ||
import type { OmniContractFactory } from '@layerzerolabs/utils-evm' | ||
import type { Uln302Factory } from '@layerzerolabs/protocol-utils' | ||
import { Uln302 } from './sdk' | ||
|
||
/** | ||
* Syntactic sugar that creates an instance of EVM `Uln302` SDK | ||
* based on an `OmniPoint` with help of an `OmniContractFactory` | ||
* | ||
* @param {OmniContractFactory} contractFactory | ||
* @returns {Uln302Factory<Uln302>} | ||
*/ | ||
export const createUln302Factory = (contractFactory: OmniContractFactory): Uln302Factory<Uln302> => | ||
pMemoize(async (point) => new Uln302(await contractFactory(point))) |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './factory' | ||
export * from './sdk' | ||
export * from './types' |
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,65 @@ | ||
import fc from 'fast-check' | ||
import { endpointArbitrary, evmAddressArbitrary } from '@layerzerolabs/test-utils' | ||
import type { Contract } from '@ethersproject/contracts' | ||
import { isZero, makeBytes32, makeZeroAddress, type OmniContract } from '@layerzerolabs/utils-evm' | ||
import { Endpoint } from '@/endpoint' | ||
|
||
describe('endpoint/sdk', () => { | ||
describe('getUln302SDK', () => { | ||
const zeroishAddressArbitrary = fc.constantFrom(makeZeroAddress(), makeBytes32()) | ||
const jestFunctionArbitrary = fc.anything().map(() => jest.fn()) | ||
const oappOmniContractArbitrary = fc.record({ | ||
address: evmAddressArbitrary, | ||
peers: jestFunctionArbitrary, | ||
endpoint: jestFunctionArbitrary, | ||
interface: fc.record({ | ||
encodeFunctionData: jestFunctionArbitrary, | ||
}), | ||
}) as fc.Arbitrary<unknown> as fc.Arbitrary<Contract> | ||
|
||
const omniContractArbitrary: fc.Arbitrary<OmniContract> = fc.record({ | ||
eid: endpointArbitrary, | ||
contract: oappOmniContractArbitrary, | ||
}) | ||
|
||
const uln302Factory = jest.fn().mockRejectedValue('No endpoint') | ||
|
||
it('should reject if the address is a zeroish address', async () => { | ||
await fc.assert( | ||
fc.asyncProperty(omniContractArbitrary, zeroishAddressArbitrary, async (omniContract, address) => { | ||
const sdk = new Endpoint(omniContract, uln302Factory) | ||
|
||
await expect(sdk.getUln302SDK(address)).rejects.toThrow( | ||
/Uln302 cannot be instantiated: Uln302 address cannot be a zero value for Endpoint/ | ||
) | ||
}) | ||
) | ||
}) | ||
|
||
it('should call the uln302Factory if the address is a non-zeroish address', async () => { | ||
await fc.assert( | ||
fc.asyncProperty( | ||
omniContractArbitrary, | ||
evmAddressArbitrary, | ||
fc.anything(), | ||
async (omniContract, address, uln302Sdk) => { | ||
fc.pre(!isZero(address)) | ||
|
||
uln302Factory.mockReset().mockResolvedValue(uln302Sdk) | ||
|
||
const sdk = new Endpoint(omniContract, uln302Factory) | ||
const uln302 = await sdk.getUln302SDK(address) | ||
|
||
expect(uln302).toBe(uln302Sdk) | ||
|
||
expect(uln302Factory).toHaveBeenCalledTimes(1) | ||
expect(uln302Factory).toHaveBeenCalledWith({ | ||
eid: omniContract.eid, | ||
address, | ||
}) | ||
} | ||
) | ||
) | ||
}) | ||
}) | ||
}) |
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
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
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