Merge remote-tracking branch 'origin/main' into pack_ixns
This commit is contained in:
commit
5effecb187
|
@ -272,8 +272,9 @@ export class SwitchboardTestContext implements ISwitchboardTestContext {
|
|||
try {
|
||||
mint = await queue.loadMint();
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
throw new Error(
|
||||
`Failed to load the SBV2 mint for the given cluster, ${error.message}`
|
||||
`Failed to load the SBV2 mint for the given cluster, ${error}`
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -291,7 +291,7 @@ wallet = "${this.payerKeypairPath}"
|
|||
startup_wait = 10000
|
||||
|
||||
[test.validator]
|
||||
url = "https://devnet.genesysgo.net/"
|
||||
url = "https://api.devnet.solana.com"
|
||||
|
||||
[[test.validator.clone]] # programID
|
||||
address = "${this.programId}"
|
||||
|
|
|
@ -1526,7 +1526,7 @@ export class JobAccount {
|
|||
payer: payerKeypair.publicKey,
|
||||
systemProgram: SystemProgram.programId,
|
||||
})
|
||||
// .signers()
|
||||
.signers([payerKeypair, jobKeypair])
|
||||
.rpc();
|
||||
} else {
|
||||
const chunks: Buffer[] = [];
|
||||
|
@ -1557,6 +1557,7 @@ export class JobAccount {
|
|||
payer: payerKeypair.publicKey,
|
||||
systemProgram: SystemProgram.programId,
|
||||
})
|
||||
.signers([payerKeypair, jobKeypair])
|
||||
.rpc()
|
||||
);
|
||||
|
||||
|
|
|
@ -1,67 +1,70 @@
|
|||
import * as borsh from "@project-serum/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||
import { Connection, PublicKey } from "@solana/web3.js"
|
||||
import { PROGRAM_ID } from "../programId"
|
||||
import * as borsh from "@project-serum/borsh"; // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||
import { Connection, PublicKey } from "@solana/web3.js";
|
||||
import { PROGRAM_ID } from "../programId";
|
||||
|
||||
export interface BufferClientFields {}
|
||||
|
||||
export interface BufferClientJSON {}
|
||||
|
||||
export class BufferClient {
|
||||
static readonly discriminator = Buffer.from([142, 182, 89, 69, 9, 66, 10, 86])
|
||||
static readonly discriminator = Buffer.from([
|
||||
142, 182, 89, 69, 9, 66, 10, 86,
|
||||
]);
|
||||
|
||||
static readonly layout = borsh.struct([])
|
||||
static readonly layout = borsh.struct([]);
|
||||
|
||||
constructor(fields: BufferClientFields) {}
|
||||
|
||||
static async fetch(
|
||||
c: Connection,
|
||||
programId: PublicKey,
|
||||
address: PublicKey
|
||||
): Promise<BufferClient | null> {
|
||||
const info = await c.getAccountInfo(address)
|
||||
const info = await c.getAccountInfo(address);
|
||||
|
||||
if (info === null) {
|
||||
return null
|
||||
return null;
|
||||
}
|
||||
if (!info.owner.equals(PROGRAM_ID)) {
|
||||
throw new Error("account doesn't belong to this program")
|
||||
throw new Error("account doesn't belong to this program");
|
||||
}
|
||||
|
||||
return this.decode(info.data)
|
||||
return this.decode(info.data);
|
||||
}
|
||||
|
||||
static async fetchMultiple(
|
||||
c: Connection,
|
||||
addresses: PublicKey[]
|
||||
): Promise<Array<BufferClient | null>> {
|
||||
const infos = await c.getMultipleAccountsInfo(addresses)
|
||||
const infos = await c.getMultipleAccountsInfo(addresses);
|
||||
|
||||
return infos.map((info) => {
|
||||
if (info === null) {
|
||||
return null
|
||||
return null;
|
||||
}
|
||||
if (!info.owner.equals(PROGRAM_ID)) {
|
||||
throw new Error("account doesn't belong to this program")
|
||||
throw new Error("account doesn't belong to this program");
|
||||
}
|
||||
|
||||
return this.decode(info.data)
|
||||
})
|
||||
return this.decode(info.data);
|
||||
});
|
||||
}
|
||||
|
||||
static decode(data: Buffer): BufferClient {
|
||||
if (!data.slice(0, 8).equals(BufferClient.discriminator)) {
|
||||
throw new Error("invalid account discriminator")
|
||||
throw new Error("invalid account discriminator");
|
||||
}
|
||||
|
||||
const dec = BufferClient.layout.decode(data.slice(8))
|
||||
const dec = BufferClient.layout.decode(data.slice(8));
|
||||
|
||||
return new BufferClient({})
|
||||
return new BufferClient({});
|
||||
}
|
||||
|
||||
toJSON(): BufferClientJSON {
|
||||
return {}
|
||||
return {};
|
||||
}
|
||||
|
||||
static fromJSON(obj: BufferClientJSON): BufferClient {
|
||||
return new BufferClient({})
|
||||
return new BufferClient({});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as borsh from "@project-serum/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||
import { Connection, PublicKey } from "@solana/web3.js"
|
||||
import { PROGRAM_ID } from "../programId"
|
||||
import * as borsh from "@project-serum/borsh"; // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||
import { Connection, PublicKey } from "@solana/web3.js";
|
||||
import { PROGRAM_ID } from "../programId";
|
||||
|
||||
export interface FeedClientFields {}
|
||||
|
||||
|
@ -9,61 +9,62 @@ export interface FeedClientJSON {}
|
|||
export class FeedClient {
|
||||
static readonly discriminator = Buffer.from([
|
||||
30, 15, 152, 236, 85, 180, 84, 151,
|
||||
])
|
||||
]);
|
||||
|
||||
static readonly layout = borsh.struct([])
|
||||
static readonly layout = borsh.struct([]);
|
||||
|
||||
constructor(fields: FeedClientFields) {}
|
||||
|
||||
static async fetch(
|
||||
c: Connection,
|
||||
programId: PublicKey,
|
||||
address: PublicKey
|
||||
): Promise<FeedClient | null> {
|
||||
const info = await c.getAccountInfo(address)
|
||||
const info = await c.getAccountInfo(address);
|
||||
|
||||
if (info === null) {
|
||||
return null
|
||||
return null;
|
||||
}
|
||||
if (!info.owner.equals(PROGRAM_ID)) {
|
||||
throw new Error("account doesn't belong to this program")
|
||||
throw new Error("account doesn't belong to this program");
|
||||
}
|
||||
|
||||
return this.decode(info.data)
|
||||
return this.decode(info.data);
|
||||
}
|
||||
|
||||
static async fetchMultiple(
|
||||
c: Connection,
|
||||
addresses: PublicKey[]
|
||||
): Promise<Array<FeedClient | null>> {
|
||||
const infos = await c.getMultipleAccountsInfo(addresses)
|
||||
const infos = await c.getMultipleAccountsInfo(addresses);
|
||||
|
||||
return infos.map((info) => {
|
||||
if (info === null) {
|
||||
return null
|
||||
return null;
|
||||
}
|
||||
if (!info.owner.equals(PROGRAM_ID)) {
|
||||
throw new Error("account doesn't belong to this program")
|
||||
throw new Error("account doesn't belong to this program");
|
||||
}
|
||||
|
||||
return this.decode(info.data)
|
||||
})
|
||||
return this.decode(info.data);
|
||||
});
|
||||
}
|
||||
|
||||
static decode(data: Buffer): FeedClient {
|
||||
if (!data.slice(0, 8).equals(FeedClient.discriminator)) {
|
||||
throw new Error("invalid account discriminator")
|
||||
throw new Error("invalid account discriminator");
|
||||
}
|
||||
|
||||
const dec = FeedClient.layout.decode(data.slice(8))
|
||||
const dec = FeedClient.layout.decode(data.slice(8));
|
||||
|
||||
return new FeedClient({})
|
||||
return new FeedClient({});
|
||||
}
|
||||
|
||||
toJSON(): FeedClientJSON {
|
||||
return {}
|
||||
return {};
|
||||
}
|
||||
|
||||
static fromJSON(obj: FeedClientJSON): FeedClient {
|
||||
return new FeedClient({})
|
||||
return new FeedClient({});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,4 +23,49 @@ test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 ./tests/*.test.ts"
|
|||
url="https://api.devnet.solana.com"
|
||||
|
||||
[[testnet.validator.clone]]
|
||||
address="GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR" # sbv2 SOL/USD Feed
|
||||
address="GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR" # sbv2 SOL/USD Feed
|
||||
|
||||
[test]
|
||||
startup_wait = 10000
|
||||
|
||||
[[test.validator.clone]] # programID
|
||||
address = "2TfB33aLaneQb5TNVwyDz3jSZXS6jdW2ARw1Dgf84XCG"
|
||||
|
||||
[[test.validator.clone]] # idlAddress
|
||||
address = "CKwZcshn4XDvhaWVH9EXnk3iu19t6t5xP2Sy2pD6TRDp"
|
||||
|
||||
[[test.validator.clone]] # programState
|
||||
address = "BYM81n8HvTJuqZU1PmTVcwZ9G8uoji7FKM6EaPkwphPt"
|
||||
|
||||
[[test.validator.clone]] # switchboardVault
|
||||
address = "FVLfR6C2ckZhbSwBzZY4CX7YBcddUSge5BNeGQv5eKhy"
|
||||
|
||||
[[test.validator.clone]] # tokenWallet
|
||||
address = "98noixB6NnabjgFKw9wgXtqVd9Xg6rmj5kEVMeCHUB5e"
|
||||
|
||||
[[test.validator.clone]] # queue
|
||||
address = "FTPhaHC1dEj4UNXGcp2r9T87B5jxnFU6emxEUpRqAx6A"
|
||||
|
||||
[[test.validator.clone]] # queueAuthority
|
||||
address = "AXrbiv8bmcJfscyYWjR8BMFvTUjmx7FSENCjtEx4NxFh"
|
||||
|
||||
[[test.validator.clone]] # queueBuffer
|
||||
address = "FgZfUbf4qEUcK6WMWnH2U9VvQnYfBiFgTgV83qbLmfaa"
|
||||
|
||||
[[test.validator.clone]] # crank
|
||||
address = "28x9auDSau1MmJr57wdDUBk1qXQoktz7mkW1ueT5hpe8"
|
||||
|
||||
[[test.validator.clone]] # crankBuffer
|
||||
address = "EmbyiARb7cJSJAdB8dWRVpsrHfGed3Pq9LZR8L3LfdQq"
|
||||
|
||||
[[test.validator.clone]] # oracle
|
||||
address = "GmrXk527KuzNDsn9LnnRKeiTjgaut58gBfZ7qpmiU5yP"
|
||||
|
||||
[[test.validator.clone]] # oracleAuthority
|
||||
address = "AXrbiv8bmcJfscyYWjR8BMFvTUjmx7FSENCjtEx4NxFh"
|
||||
|
||||
[[test.validator.clone]] # oracleEscrow
|
||||
address = "4ZxDxkACGAmDKqJFnQPf95uCJwuH1p6FAQnRgKiUr1oo"
|
||||
|
||||
[[test.validator.clone]] # oraclePermissions
|
||||
address = "AYjx3BfH4emjWPMUxTFUNntLC5dhQKzuWfX4HbgDUSwr"
|
||||
|
|
|
@ -1,40 +1,40 @@
|
|||
import * as borsh from "@project-serum/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||
import { Connection, PublicKey } from "@solana/web3.js"
|
||||
import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||
import { PROGRAM_ID } from "../programId"
|
||||
import * as borsh from "@project-serum/borsh"; // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||
import { Connection, PublicKey } from "@solana/web3.js";
|
||||
import BN from "bn.js"; // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||
import { PROGRAM_ID } from "../programId";
|
||||
|
||||
export interface VrfClientFields {
|
||||
bump: number
|
||||
maxResult: BN
|
||||
resultBuffer: Array<number>
|
||||
result: BN
|
||||
lastTimestamp: BN
|
||||
authority: PublicKey
|
||||
vrf: PublicKey
|
||||
bump: number;
|
||||
maxResult: BN;
|
||||
resultBuffer: Array<number>;
|
||||
result: BN;
|
||||
lastTimestamp: BN;
|
||||
authority: PublicKey;
|
||||
vrf: PublicKey;
|
||||
}
|
||||
|
||||
export interface VrfClientJSON {
|
||||
bump: number
|
||||
maxResult: string
|
||||
resultBuffer: Array<number>
|
||||
result: string
|
||||
lastTimestamp: string
|
||||
authority: string
|
||||
vrf: string
|
||||
bump: number;
|
||||
maxResult: string;
|
||||
resultBuffer: Array<number>;
|
||||
result: string;
|
||||
lastTimestamp: string;
|
||||
authority: string;
|
||||
vrf: string;
|
||||
}
|
||||
|
||||
export class VrfClient {
|
||||
readonly bump: number
|
||||
readonly maxResult: BN
|
||||
readonly resultBuffer: Array<number>
|
||||
readonly result: BN
|
||||
readonly lastTimestamp: BN
|
||||
readonly authority: PublicKey
|
||||
readonly vrf: PublicKey
|
||||
readonly bump: number;
|
||||
readonly maxResult: BN;
|
||||
readonly resultBuffer: Array<number>;
|
||||
readonly result: BN;
|
||||
readonly lastTimestamp: BN;
|
||||
readonly authority: PublicKey;
|
||||
readonly vrf: PublicKey;
|
||||
|
||||
static readonly discriminator = Buffer.from([
|
||||
230, 174, 157, 153, 51, 18, 230, 163,
|
||||
])
|
||||
]);
|
||||
|
||||
static readonly layout = borsh.struct([
|
||||
borsh.u8("bump"),
|
||||
|
@ -44,58 +44,59 @@ export class VrfClient {
|
|||
borsh.i64("lastTimestamp"),
|
||||
borsh.publicKey("authority"),
|
||||
borsh.publicKey("vrf"),
|
||||
])
|
||||
]);
|
||||
|
||||
constructor(fields: VrfClientFields) {
|
||||
this.bump = fields.bump
|
||||
this.maxResult = fields.maxResult
|
||||
this.resultBuffer = fields.resultBuffer
|
||||
this.result = fields.result
|
||||
this.lastTimestamp = fields.lastTimestamp
|
||||
this.authority = fields.authority
|
||||
this.vrf = fields.vrf
|
||||
this.bump = fields.bump;
|
||||
this.maxResult = fields.maxResult;
|
||||
this.resultBuffer = fields.resultBuffer;
|
||||
this.result = fields.result;
|
||||
this.lastTimestamp = fields.lastTimestamp;
|
||||
this.authority = fields.authority;
|
||||
this.vrf = fields.vrf;
|
||||
}
|
||||
|
||||
static async fetch(
|
||||
c: Connection,
|
||||
programId: PublicKey,
|
||||
address: PublicKey
|
||||
): Promise<VrfClient | null> {
|
||||
const info = await c.getAccountInfo(address)
|
||||
const info = await c.getAccountInfo(address);
|
||||
|
||||
if (info === null) {
|
||||
return null
|
||||
return null;
|
||||
}
|
||||
if (!info.owner.equals(PROGRAM_ID)) {
|
||||
throw new Error("account doesn't belong to this program")
|
||||
throw new Error("account doesn't belong to this program");
|
||||
}
|
||||
|
||||
return this.decode(info.data)
|
||||
return this.decode(info.data);
|
||||
}
|
||||
|
||||
static async fetchMultiple(
|
||||
c: Connection,
|
||||
addresses: PublicKey[]
|
||||
): Promise<Array<VrfClient | null>> {
|
||||
const infos = await c.getMultipleAccountsInfo(addresses)
|
||||
const infos = await c.getMultipleAccountsInfo(addresses);
|
||||
|
||||
return infos.map((info) => {
|
||||
if (info === null) {
|
||||
return null
|
||||
return null;
|
||||
}
|
||||
if (!info.owner.equals(PROGRAM_ID)) {
|
||||
throw new Error("account doesn't belong to this program")
|
||||
throw new Error("account doesn't belong to this program");
|
||||
}
|
||||
|
||||
return this.decode(info.data)
|
||||
})
|
||||
return this.decode(info.data);
|
||||
});
|
||||
}
|
||||
|
||||
static decode(data: Buffer): VrfClient {
|
||||
if (!data.slice(0, 8).equals(VrfClient.discriminator)) {
|
||||
throw new Error("invalid account discriminator")
|
||||
throw new Error("invalid account discriminator");
|
||||
}
|
||||
|
||||
const dec = VrfClient.layout.decode(data.slice(8))
|
||||
const dec = VrfClient.layout.decode(data.slice(8));
|
||||
|
||||
return new VrfClient({
|
||||
bump: dec.bump,
|
||||
|
@ -105,7 +106,7 @@ export class VrfClient {
|
|||
lastTimestamp: dec.lastTimestamp,
|
||||
authority: dec.authority,
|
||||
vrf: dec.vrf,
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
toJSON(): VrfClientJSON {
|
||||
|
@ -117,7 +118,7 @@ export class VrfClient {
|
|||
lastTimestamp: this.lastTimestamp.toString(),
|
||||
authority: this.authority.toString(),
|
||||
vrf: this.vrf.toString(),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static fromJSON(obj: VrfClientJSON): VrfClient {
|
||||
|
@ -129,6 +130,6 @@ export class VrfClient {
|
|||
lastTimestamp: new BN(obj.lastTimestamp),
|
||||
authority: new PublicKey(obj.authority),
|
||||
vrf: new PublicKey(obj.vrf),
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
} from "@solana/web3.js";
|
||||
import {
|
||||
promiseWithTimeout,
|
||||
sleep,
|
||||
SwitchboardTestContext,
|
||||
} from "@switchboard-xyz/sbv2-utils";
|
||||
import {
|
||||
|
@ -88,6 +89,7 @@ describe("anchor-vrf-parser test", () => {
|
|||
return;
|
||||
} catch (error: any) {
|
||||
console.log(`Error: SBV2 Localnet - ${error.message}`);
|
||||
console.error(error);
|
||||
}
|
||||
// If fails, throw error
|
||||
throw new Error(
|
||||
|
@ -95,6 +97,40 @@ describe("anchor-vrf-parser test", () => {
|
|||
);
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
const maxTime = 60000;
|
||||
const retryCount = 10;
|
||||
const retryInterval = maxTime / retryCount;
|
||||
let isReady = false;
|
||||
const timer = setInterval(async () => {
|
||||
const queue = await switchboard.queue.loadData();
|
||||
const oracles = queue.queueData as anchor.web3.PublicKey[];
|
||||
if (oracles.length) {
|
||||
console.log(`oracle ready, ${oracles.length}`);
|
||||
isReady = true;
|
||||
clearTimeout(timer);
|
||||
} else {
|
||||
console.log(`oracle not ready, ${oracles.length}`);
|
||||
}
|
||||
}, retryInterval);
|
||||
|
||||
let n = maxTime / 1000;
|
||||
while (!isReady && n > 0) {
|
||||
if (isReady) {
|
||||
console.log(`finally ready`);
|
||||
break;
|
||||
}
|
||||
console.log(`still not ready ${n} ...`);
|
||||
await sleep(1 * 1000);
|
||||
--n;
|
||||
}
|
||||
if (!isReady) {
|
||||
throw new Error(`Docker oracle failed to initialize in 60seconds`);
|
||||
}
|
||||
|
||||
clearTimeout(timer);
|
||||
});
|
||||
|
||||
it("Creates a vrfClient account", async () => {
|
||||
const queue = switchboard.queue;
|
||||
const { unpermissionedVrfEnabled, authority, dataBuffer } =
|
||||
|
@ -199,7 +235,7 @@ describe("anchor-vrf-parser test", () => {
|
|||
const result = await awaitCallback(
|
||||
vrfClientProgram.provider.connection,
|
||||
vrfClientKey,
|
||||
55_000
|
||||
155_000
|
||||
);
|
||||
|
||||
console.log(`VrfClient Result: ${result}`);
|
||||
|
|
Loading…
Reference in New Issue