Skip to content

Commit

Permalink
- Updated assertions comparing numbers in tests to use .eq() method i…
Browse files Browse the repository at this point in the history
…n place of ===

- changed anchor.BN to BN
- Wrapped solPrice with BN

 - Renamed tx to transaction in the burry-escrow.ts

- Wrapped solPrice with BN

- renamed e to error for more clarity

- changed switchboard_solana back to switchboard_v2 since vrf is not yet supported in switchboard_solana
  • Loading branch information
adpthegreat committed Sep 12, 2024
1 parent 7f4183c commit 0d7ffa5
Showing 1 changed file with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ called a seed and then use mathematical formulas to generate subsequent numbers
in the sequence. Given the same seed, a PRNG will always produce the same
sequence of numbers. It's important to seed with something close to true
entropy: an admin-provided "random" input, the last system log, some combination
of your system's clock time and other factors, etc.. Fun fact: older video games
of your system's clock time and other factors, etc.. Fun fact: some older video games
have been broken because speedrunners found out how their randomness was
calculated. One game in particular used the number of steps you've taken in the
game as a seed.
Expand Down Expand Up @@ -329,7 +329,7 @@ or `invoke_signed` on the object.

```rust
// our client program
use switchboard_solana::VrfRequestRandomness;
use switchboard_v2::VrfRequestRandomness;
use state::*;

pub fn request_randomness(ctx: Context<RequestRandomness>, request_params: RequestRandomnessParams) -> Result <()> {
Expand Down Expand Up @@ -482,9 +482,9 @@ in our `Cargo.toml` file.

```typescript
[dependencies]
anchor-lang = "0.30.1"
anchor-spl = "0.30.1"
switchboard-solana = "0.30.4"
anchor-lang = "0.28.0"
anchor-spl = "0.28.0"
switchboard-v2 = "0.4.0"
```

### 3. Lib.rs
Expand Down Expand Up @@ -738,7 +738,7 @@ the following accounts:
use crate::state::*;
use crate::errors::*;
use anchor_lang::prelude::*;
use switchboard_solana::VrfAccountData;
use switchboard_v2::VrfAccountData;

pub const ANCHOR_DISCRIMINATOR: usize = 8;

Expand Down Expand Up @@ -1016,7 +1016,7 @@ three accounts.
use crate::state::*;
use crate::errors::*;
use anchor_lang::prelude::*;
use switchboard_solana::VrfAccountData;
use switchboard_v2::VrfAccountData;

#[derive(Accounts)]
pub struct ConsumeRandomness<'info> {
Expand Down Expand Up @@ -1211,13 +1211,13 @@ file:

```toml
## VRF ACCOUNTS
[[test.validator.clone]] # Switchboard Solana attestation programID
[[test.validator.clone]] # Sbv2 attestation programID
address = "sbattyXrzedoNATfc4L31wC9Mhxsi1BmFhTiN8gDshx"

[[test.validator.clone]] # Switchboard Solana attestation IDL
[[test.validator.clone]] # Sbv2 attestation IDL
address = "5ExuoQR69trmKQfB95fDsUGsUrrChbGq9PFgt8qouncz"

[[test.validator.clone]] # Switchboard Solana SbState
[[test.validator.clone]] # Sbv2 SbState
address = "CyZuD7RPDcrqCGbNvLCyqk6Py9cEZTKmNKujfPi3ynDd"
```

Expand All @@ -1227,7 +1227,7 @@ imports, and adds a new function called `delay`.

```typescript
import * as anchor from "@coral-xyz/anchor";
import { Program } from "@coral-xyz/anchor";
import { Program , BN } from "@coral-xyz/anchor";
import { BurryEscrow } from "../target/types/burry_escrow";
import { Big } from "@switchboard-xyz/common";
import {
Expand Down Expand Up @@ -1265,7 +1265,7 @@ describe("burry-escrow-vrf", () => {
);
const aggregatorAccount = new AggregatorAccount(
switchboardProgram,
solUsedSwitchboardFeed,
solUsdSwitchboardFeed,
);

// derive escrow state account
Expand All @@ -1280,12 +1280,12 @@ describe("burry-escrow-vrf", () => {
if (solPrice === null) {
throw new Error("Aggregator holds no value");
}
const failUnlockPrice = solPrice.plus(10).toNumber();
const amountToLockUp = new anchor.BN(100);
const failUnlockPrice = new BN(solPrice.plus(10).toNumber());
const amountToLockUp = new BN(100);

// Send transaction
try {
const tx = await program.methods
const transaction = await program.methods
.deposit(amountToLockUp, failUnlockPrice)
.accounts({
user: payer.publicKey,
Expand All @@ -1295,8 +1295,8 @@ describe("burry-escrow-vrf", () => {
.signers([payer])
.rpc();

await provider.connection.confirmTransaction(tx, "confirmed");
console.log("Your transaction signature", tx);
await provider.connection.confirmTransaction(transaction, "confirmed");
console.log("Your transaction signature", transaction);

// Fetch the created account
const newAccount = await program.account.escrow.fetch(Escrow);
Expand All @@ -1309,7 +1309,7 @@ describe("burry-escrow-vrf", () => {
console.log("Amount in escrow:", escrowBalance);

// Check whether the data onchain is equal to local 'data'
assert(failUnlockPrice == newAccount.unlockPrice);
assert(failUnlockPrice.eq(newAccount.unlockPrice));
assert(escrowBalance > 0);
} catch (error) {
console.log(error);
Expand All @@ -1326,9 +1326,9 @@ describe("burry-escrow-vrf", () => {
program.programId,
);

// send tx
// send transaction
try {
const tx = await program.methods
const transaction = await program.methods
.withdraw()
.accounts({
user: payer.publicKey,
Expand All @@ -1339,13 +1339,13 @@ describe("burry-escrow-vrf", () => {
.signers([payer])
.rpc();

await provider.connection.confirmTransaction(tx, "confirmed");
console.log("Your transaction signature", tx);
await provider.connection.confirmTransaction(transaction, "confirmed");
console.log("Your transaction signature", transaction);
} catch (error) {
didFail = true;

assert(
error.message.includes(
error.errorMessage.includes(
"Current SOL price is not above Escrow unlock price.",
),
"Unexpected error message: " + error.message,
Expand Down Expand Up @@ -1507,7 +1507,7 @@ it("Roll till you can withdraw", async () => {

// initialize vrf client
try {
const tx = await program.methods
const transaction = await program.methods
.initVrfClient()
.accounts({
user: payer.publicKey,
Expand All @@ -1527,7 +1527,7 @@ it("Roll till you can withdraw", async () => {
while (!rolledDoubles) {
try {
// Request randomness and roll dice
const tx = await program.methods
const transaction = await program.methods
.getOutOfJail({
switchboardStateBump: switchboard.program.programState.bump,
permissionBump,
Expand All @@ -1553,7 +1553,7 @@ it("Roll till you can withdraw", async () => {
.signers([payer])
.rpc();

await provider.connection.confirmTransaction(tx, "confirmed");
await provider.connection.confirmTransaction(transaction, "confirmed");
console.log(`Created VrfClient Account: ${vrfClientKey}`);

// wait a few sec for switchboard to generate the random number and invoke callback instruction
Expand Down Expand Up @@ -1587,7 +1587,7 @@ it("Roll till you can withdraw", async () => {
}
}

const tx = await program.methods
const transaction = await program.methods
.withdraw()
.accounts({
user: payer.publicKey,
Expand All @@ -1598,7 +1598,7 @@ it("Roll till you can withdraw", async () => {
.signers([payer])
.rpc();

await provider.connection.confirmTransaction(tx, "confirmed");
await provider.connection.confirmTransaction(transaction, "confirmed");
});
```
Expand Down

0 comments on commit 0d7ffa5

Please sign in to comment.