-
Notifications
You must be signed in to change notification settings - Fork 175
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
5b9938a
commit 63d7785
Showing
7 changed files
with
100 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './schema' | ||
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,9 @@ | ||
import { z } from 'zod' | ||
import BN from 'bn.js' | ||
import { PublicKey } from '@solana/web3.js' | ||
|
||
export const BNBigIntSchema = z.instanceof(BN).transform((bn) => BigInt(bn.toString())) | ||
|
||
export const PublicKeySchema = z.instanceof(PublicKey) | ||
|
||
export const PublicKeyBase58Schema = PublicKeySchema.transform((key) => key.toBase58()) |
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,47 @@ | ||
import { BNBigIntSchema, PublicKeySchema } from '@/common/schema' | ||
import { keypairArbitrary } from '@layerzerolabs/test-devtools-solana' | ||
import BN from 'bn.js' | ||
import fc from 'fast-check' | ||
|
||
describe('common/schema', () => { | ||
describe('BNBigIntSchema', () => { | ||
const bnArbitrary: fc.Arbitrary<BN> = fc.bigInt().map((value) => new BN(value.toString())) | ||
|
||
it('should parse a BN instance', () => { | ||
fc.assert( | ||
fc.property(bnArbitrary, (bn) => { | ||
expect(BNBigIntSchema.parse(bn)).toBe(BigInt(bn.toString())) | ||
}) | ||
) | ||
}) | ||
|
||
it('should not parse anything else', () => { | ||
fc.assert( | ||
fc.property(fc.anything(), (value) => { | ||
expect(() => BNBigIntSchema.parse(value)).toThrow(/Input not instance of BN/) | ||
}) | ||
) | ||
}) | ||
}) | ||
|
||
describe('PublicKeySchema', () => { | ||
it('should parse a PublicKey instance', () => { | ||
fc.assert( | ||
fc.property( | ||
keypairArbitrary.map((keypair) => keypair.publicKey), | ||
(publicKey) => { | ||
expect(PublicKeySchema.parse(publicKey)).toBe(publicKey) | ||
} | ||
) | ||
) | ||
}) | ||
|
||
it('should not parse anything else', () => { | ||
fc.assert( | ||
fc.property(fc.anything(), (value) => { | ||
expect(() => PublicKeySchema.parse(value)).toThrow(/Input not instance of PublicKey/) | ||
}) | ||
) | ||
}) | ||
}) | ||
}) |
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,18 @@ | ||
import { UIntBigIntSchema, UIntNumberSchema } from '@layerzerolabs/devtools' | ||
import { BNBigIntSchema, PublicKeyBase58Schema } from '@layerzerolabs/devtools-solana' | ||
import { Uln302UlnConfig } from '@layerzerolabs/protocol-devtools' | ||
import { z } from 'zod' | ||
|
||
export const Uln302UlnConfigInputSchema: z.ZodSchema<Uln302UlnConfig, z.ZodTypeDef, unknown> = z | ||
.object({ | ||
confirmations: z.union([UIntBigIntSchema, BNBigIntSchema]), | ||
optionalDvnThreshold: UIntNumberSchema, | ||
requiredDvns: z.array(PublicKeyBase58Schema), | ||
optionalDvns: z.array(PublicKeyBase58Schema), | ||
}) | ||
.transform(({ confirmations, optionalDvnThreshold, requiredDvns, optionalDvns }) => ({ | ||
confirmations, | ||
optionalDVNThreshold: optionalDvnThreshold, | ||
requiredDVNs: requiredDvns, | ||
optionalDVNs: optionalDvns, | ||
})) |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.