Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
armaniferrante committed May 25, 2021
1 parent b58a382 commit e3e83a6
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 53 deletions.
4 changes: 2 additions & 2 deletions examples/cashiers-check/tests/cashiers-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe("cashiers-check", () => {
],
});

const checkAccount = await program.account.check(check.publicKey);
const checkAccount = await program.account.check.fetch(check.publicKey);
assert.ok(checkAccount.from.equals(god));
assert.ok(checkAccount.to.equals(receiver));
assert.ok(checkAccount.amount.eq(new anchor.BN(100)));
Expand Down Expand Up @@ -91,7 +91,7 @@ describe("cashiers-check", () => {
},
});

const checkAccount = await program.account.check(check.publicKey);
const checkAccount = await program.account.check.fetch(check.publicKey);
assert.ok(checkAccount.burned === true);

let vaultAccount = await serumCmn.getTokenAccount(
Expand Down
4 changes: 2 additions & 2 deletions examples/chat/tests/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("chat", () => {
signers: [chatRoom],
});

const chat = await program.account.chatRoom(chatRoom.publicKey);
const chat = await program.account.chatRoom.fetch(chatRoom.publicKey);
const name = new TextDecoder("utf-8").decode(new Uint8Array(chat.name));
assert.ok(name.startsWith("Test Chat")); // [u8; 280] => trailing zeros.
assert.ok(chat.messages.length === 33607);
Expand Down Expand Up @@ -76,7 +76,7 @@ describe("chat", () => {
}

// Check the chat room state is as expected.
const chat = await program.account.chatRoom(chatRoom.publicKey);
const chat = await program.account.chatRoom.fetch(chatRoom.publicKey);
const name = new TextDecoder("utf-8").decode(new Uint8Array(chat.name));
assert.ok(name.startsWith("Test Chat")); // [u8; 280] => trailing zeros.
assert.ok(chat.messages.length === 33607);
Expand Down
4 changes: 2 additions & 2 deletions examples/composite/tests/composite.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ describe("composite", () => {
}
);

const dummyAAccount = await program.account.dummyA(dummyA.publicKey);
const dummyBAccount = await program.account.dummyB(dummyB.publicKey);
const dummyAAccount = await program.account.dummyA.fetch(dummyA.publicKey);
const dummyBAccount = await program.account.dummyB.fetch(dummyB.publicKey);

assert.ok(dummyAAccount.data.eq(new anchor.BN(1234)));
assert.ok(dummyBAccount.data.eq(new anchor.BN(4321)));
Expand Down
2 changes: 1 addition & 1 deletion examples/interface/tests/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("interface", () => {
it("Is initialized!", async () => {
await counter.state.rpc.new(counterAuth.programId);

const stateAccount = await counter.state();
const stateAccount = await counter.state.fetch();
assert.ok(stateAccount.count.eq(new anchor.BN(0)));
assert.ok(stateAccount.authProgram.equals(counterAuth.programId));
});
Expand Down
34 changes: 17 additions & 17 deletions examples/lockup/tests/lockup.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe("Lockup and Registry", () => {
});

lockupAddress = await lockup.state.address();
const lockupAccount = await lockup.state();
const lockupAccount = await lockup.state.fetch();

assert.ok(lockupAccount.authority.equals(provider.wallet.publicKey));
assert.ok(lockupAccount.whitelist.length === WHITELIST_SIZE);
Expand All @@ -63,7 +63,7 @@ describe("Lockup and Registry", () => {
},
});

let lockupAccount = await lockup.state();
let lockupAccount = await lockup.state.fetch();
assert.ok(lockupAccount.authority.equals(newAuthority.publicKey));

await lockup.state.rpc.setAuthority(provider.wallet.publicKey, {
Expand All @@ -73,7 +73,7 @@ describe("Lockup and Registry", () => {
signers: [newAuthority],
});

lockupAccount = await lockup.state();
lockupAccount = await lockup.state.fetch();
assert.ok(lockupAccount.authority.equals(provider.wallet.publicKey));
});

Expand All @@ -97,7 +97,7 @@ describe("Lockup and Registry", () => {

await lockup.state.rpc.whitelistAdd(entries[0], { accounts });

let lockupAccount = await lockup.state();
let lockupAccount = await lockup.state.fetch();

assert.ok(lockupAccount.whitelist.length === 1);
assert.deepEqual(lockupAccount.whitelist, [entries[0]]);
Expand All @@ -106,7 +106,7 @@ describe("Lockup and Registry", () => {
await lockup.state.rpc.whitelistAdd(entries[k], { accounts });
}

lockupAccount = await lockup.state();
lockupAccount = await lockup.state.fetch();

assert.deepEqual(lockupAccount.whitelist, entries);

Expand All @@ -129,7 +129,7 @@ describe("Lockup and Registry", () => {
authority: provider.wallet.publicKey,
},
});
let lockupAccount = await lockup.state();
let lockupAccount = await lockup.state.fetch();
assert.deepEqual(lockupAccount.whitelist, entries.slice(1));
});

Expand Down Expand Up @@ -185,7 +185,7 @@ describe("Lockup and Registry", () => {
}
);

vestingAccount = await lockup.account.vesting(vesting.publicKey);
vestingAccount = await lockup.account.vesting.fetch(vesting.publicKey);

assert.ok(vestingAccount.beneficiary.equals(provider.wallet.publicKey));
assert.ok(vestingAccount.mint.equals(mint));
Expand Down Expand Up @@ -246,7 +246,7 @@ describe("Lockup and Registry", () => {
},
});

vestingAccount = await lockup.account.vesting(vesting.publicKey);
vestingAccount = await lockup.account.vesting.fetch(vesting.publicKey);
assert.ok(vestingAccount.outstanding.eq(new anchor.BN(0)));

const vaultAccount = await serumCmn.getTokenAccount(
Expand Down Expand Up @@ -287,7 +287,7 @@ describe("Lockup and Registry", () => {
accounts: { lockupProgram: lockup.programId },
});

const state = await registry.state();
const state = await registry.state.fetch();
assert.ok(state.lockupProgram.equals(lockup.programId));

// Should not allow a second initializatoin.
Expand Down Expand Up @@ -324,7 +324,7 @@ describe("Lockup and Registry", () => {
}
);

registrarAccount = await registry.account.registrar(registrar.publicKey);
registrarAccount = await registry.account.registrar.fetch(registrar.publicKey);

assert.ok(registrarAccount.authority.equals(provider.wallet.publicKey));
assert.equal(registrarAccount.nonce, nonce);
Expand Down Expand Up @@ -385,7 +385,7 @@ describe("Lockup and Registry", () => {

let txSigs = await provider.sendAll(allTxs);

memberAccount = await registry.account.member(member.publicKey);
memberAccount = await registry.account.member.fetch(member.publicKey);

assert.ok(memberAccount.registrar.equals(registrar.publicKey));
assert.ok(memberAccount.beneficiary.equals(provider.wallet.publicKey));
Expand Down Expand Up @@ -516,7 +516,7 @@ describe("Lockup and Registry", () => {
}
);

const vendorAccount = await registry.account.rewardVendor(
const vendorAccount = await registry.account.rewardVendor.fetch(
unlockedVendor.publicKey
);

Expand All @@ -531,7 +531,7 @@ describe("Lockup and Registry", () => {
assert.ok(vendorAccount.rewardEventQCursor === 0);
assert.deepEqual(vendorAccount.kind, rewardKind);

const rewardQAccount = await registry.account.rewardQueue(
const rewardQAccount = await registry.account.rewardQueue.fetch(
rewardQ.publicKey
);
assert.ok(rewardQAccount.head === 1);
Expand Down Expand Up @@ -571,7 +571,7 @@ describe("Lockup and Registry", () => {
let tokenAccount = await serumCmn.getTokenAccount(provider, token);
assert.ok(tokenAccount.amount.eq(new anchor.BN(200)));

const memberAccount = await registry.account.member(member.publicKey);
const memberAccount = await registry.account.member.fetch(member.publicKey);
assert.ok(memberAccount.rewardsCursor == 1);
});

Expand Down Expand Up @@ -635,7 +635,7 @@ describe("Lockup and Registry", () => {
}
);

const vendorAccount = await registry.account.rewardVendor(
const vendorAccount = await registry.account.rewardVendor.fetch(
lockedVendor.publicKey
);

Expand All @@ -653,7 +653,7 @@ describe("Lockup and Registry", () => {
JSON.stringify(lockedRewardKind)
);

const rewardQAccount = await registry.account.rewardQueue(
const rewardQAccount = await registry.account.rewardQueue.fetch(
rewardQ.publicKey
);
assert.ok(rewardQAccount.head === 2);
Expand Down Expand Up @@ -727,7 +727,7 @@ describe("Lockup and Registry", () => {
],
});

const lockupAccount = await lockup.account.vesting(
const lockupAccount = await lockup.account.vesting.fetch(
vendoredVesting.publicKey
);

Expand Down
18 changes: 9 additions & 9 deletions examples/misc/tests/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("misc", () => {
it("Can allocate extra space for a state constructor", async () => {
const tx = await program.state.rpc.new();
const addr = await program.state.address();
const state = await program.state();
const state = await program.state.fetch();
const accountInfo = await program.provider.connection.getAccountInfo(addr);
assert.ok(state.v.equals(Buffer.from([])));
assert.ok(accountInfo.data.length === 99);
Expand All @@ -32,7 +32,7 @@ describe("misc", () => {
instructions: [await program.account.data.createInstruction(data)],
}
);
const dataAccount = await program.account.data(data.publicKey);
const dataAccount = await program.account.data.fetch(data.publicKey);
assert.ok(dataAccount.udata.eq(new anchor.BN(1234)));
assert.ok(dataAccount.idata.eq(new anchor.BN(22)));
});
Expand All @@ -47,7 +47,7 @@ describe("misc", () => {
signers: [data],
instructions: [await program.account.dataU16.createInstruction(data)],
});
const dataAccount = await program.account.dataU16(data.publicKey);
const dataAccount = await program.account.dataU16.fetch(data.publicKey);
assert.ok(dataAccount.data === 99);
});

Expand Down Expand Up @@ -110,7 +110,7 @@ describe("misc", () => {
authority: program.provider.wallet.publicKey,
},
});
let stateAccount = await misc2Program.state();
let stateAccount = await misc2Program.state.fetch();
assert.ok(stateAccount.data.eq(oldData));
assert.ok(stateAccount.auth.equals(program.provider.wallet.publicKey));
const newData = new anchor.BN(2134);
Expand All @@ -121,7 +121,7 @@ describe("misc", () => {
misc2Program: misc2Program.programId,
},
});
stateAccount = await misc2Program.state();
stateAccount = await misc2Program.state.fetch();
assert.ok(stateAccount.data.eq(newData));
assert.ok(stateAccount.auth.equals(program.provider.wallet.publicKey));
});
Expand All @@ -145,7 +145,7 @@ describe("misc", () => {
);
await assert.rejects(
async () => {
await program.account.testData(associatedAccount);
await program.account.testData.fetch(associatedAccount);
},
(err) => {
assert.ok(
Expand Down Expand Up @@ -234,7 +234,7 @@ describe("misc", () => {
instructions: [await program.account.dataI8.createInstruction(data)],
signers: [data],
});
const dataAccount = await program.account.dataI8(data.publicKey);
const dataAccount = await program.account.dataI8.fetch(data.publicKey);
assert.ok(dataAccount.data === -3);
});

Expand All @@ -250,14 +250,14 @@ describe("misc", () => {
instructions: [await program.account.dataI16.createInstruction(data)],
signers: [data],
});
const dataAccount = await program.account.dataI16(data.publicKey);
const dataAccount = await program.account.dataI16.fetch(data.publicKey);
assert.ok(dataAccount.data === -2048);

dataPubkey = data.publicKey;
});

it("Can use base58 strings to fetch an account", async () => {
const dataAccount = await program.account.dataI16(dataPubkey.toString());
const dataAccount = await program.account.dataI16.fetch(dataPubkey.toString());
assert.ok(dataAccount.data === -2048);
});
});
6 changes: 3 additions & 3 deletions examples/multisig/tests/multisig.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("multisig", () => {
signers: [multisig],
});

let multisigAccount = await program.account.multisig(multisig.publicKey);
let multisigAccount = await program.account.multisig.fetch(multisig.publicKey);

assert.equal(multisigAccount.nonce, nonce);
assert.ok(multisigAccount.threshold.eq(new anchor.BN(2)));
Expand Down Expand Up @@ -81,7 +81,7 @@ describe("multisig", () => {
signers: [transaction, ownerA],
});

const txAccount = await program.account.transaction(transaction.publicKey);
const txAccount = await program.account.transaction.fetch(transaction.publicKey);

assert.ok(txAccount.programId.equals(pid));
assert.deepEqual(txAccount.accounts, accounts);
Expand Down Expand Up @@ -124,7 +124,7 @@ describe("multisig", () => {
}),
});

multisigAccount = await program.account.multisig(multisig.publicKey);
multisigAccount = await program.account.multisig.fetch(multisig.publicKey);

assert.equal(multisigAccount.nonce, nonce);
assert.ok(multisigAccount.threshold.eq(new anchor.BN(2)));
Expand Down
8 changes: 4 additions & 4 deletions examples/tutorial/basic-1/tests/basic-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe("basic-1", () => {
// #endregion code-separated

// Fetch the newly created account from the cluster.
const account = await program.account.myAccount(myAccount.publicKey);
const account = await program.account.myAccount.fetch(myAccount.publicKey);

// Check it's state was initialized.
assert.ok(account.data.eq(new anchor.BN(1234)));
Expand Down Expand Up @@ -81,7 +81,7 @@ describe("basic-1", () => {
});

// Fetch the newly created account from the cluster.
const account = await program.account.myAccount(myAccount.publicKey);
const account = await program.account.myAccount.fetch(myAccount.publicKey);

// Check it's state was initialized.
assert.ok(account.data.eq(new anchor.BN(1234)));
Expand All @@ -108,7 +108,7 @@ describe("basic-1", () => {
// #endregion code-simplified

// Fetch the newly created account from the cluster.
const account = await program.account.myAccount(myAccount.publicKey);
const account = await program.account.myAccount.fetch(myAccount.publicKey);

// Check it's state was initialized.
assert.ok(account.data.eq(new anchor.BN(1234)));
Expand All @@ -133,7 +133,7 @@ describe("basic-1", () => {
});

// Fetch the newly updated account.
const account = await program.account.myAccount(myAccount.publicKey);
const account = await program.account.myAccount.fetch(myAccount.publicKey);

// Check it's state was mutated.
assert.ok(account.data.eq(new anchor.BN(4321)));
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial/basic-2/tests/basic-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('basic-2', () => {
instructions: [await program.account.counter.createInstruction(counter)],
})

let counterAccount = await program.account.counter(counter.publicKey)
let counterAccount = await program.account.counter.fetch(counter.publicKey)

assert.ok(counterAccount.authority.equals(provider.wallet.publicKey))
assert.ok(counterAccount.count.toNumber() === 0)
Expand All @@ -37,7 +37,7 @@ describe('basic-2', () => {
},
})

const counterAccount = await program.account.counter(counter.publicKey)
const counterAccount = await program.account.counter.fetch(counter.publicKey)

assert.ok(counterAccount.authority.equals(provider.wallet.publicKey))
assert.ok(counterAccount.count.toNumber() == 1)
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial/basic-3/tests/basic-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe("basic-3", () => {
});

// Check the state updated.
puppetAccount = await puppet.account.puppet(newPuppetAccount.publicKey);
puppetAccount = await puppet.account.puppet.fetch(newPuppetAccount.publicKey);
assert.ok(puppetAccount.data.eq(new anchor.BN(111)));
});
});
2 changes: 1 addition & 1 deletion examples/tutorial/basic-4/tests/basic-4.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("basic-4", () => {
},
});
// #endregion instruction
const state = await program.state();
const state = await program.state.fetch();
assert.ok(state.count.eq(new anchor.BN(1)));
});
});
Loading

0 comments on commit e3e83a6

Please sign in to comment.