68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
|
import * as anchor from "@project-serum/anchor";
|
||
|
import { Program, getProvider } from "@project-serum/anchor";
|
||
|
import { Keypair, SystemProgram } from "@solana/web3.js";
|
||
|
import { Floats } from "../target/types/floats";
|
||
|
import assert from "assert";
|
||
|
|
||
|
describe("floats", () => {
|
||
|
// Configure the client to use the local cluster.
|
||
|
anchor.setProvider(anchor.Provider.env());
|
||
|
|
||
|
const program = anchor.workspace.Floats as Program<Floats>;
|
||
|
|
||
|
it("Creates an account with float data", async () => {
|
||
|
const accountKeypair = Keypair.generate();
|
||
|
|
||
|
await program.methods
|
||
|
.create(1.0, 2.0)
|
||
|
.accounts({
|
||
|
account: accountKeypair.publicKey,
|
||
|
authority: getProvider().wallet.publicKey,
|
||
|
systemProgram: SystemProgram.programId,
|
||
|
})
|
||
|
.signers([accountKeypair])
|
||
|
.rpc();
|
||
|
|
||
|
const account = await program.account.floatDataAccount.fetch(
|
||
|
accountKeypair.publicKey
|
||
|
);
|
||
|
|
||
|
assert.strictEqual(account.dataF32, 1.0);
|
||
|
assert.strictEqual(account.dataF64, 2.0);
|
||
|
});
|
||
|
|
||
|
it("Updates an account with float data", async () => {
|
||
|
const accountKeypair = Keypair.generate();
|
||
|
const authorityPublicKey = getProvider().wallet.publicKey;
|
||
|
|
||
|
await program.methods
|
||
|
.create(1.0, 2.0)
|
||
|
.accounts({
|
||
|
account: accountKeypair.publicKey,
|
||
|
authority: authorityPublicKey,
|
||
|
systemProgram: SystemProgram.programId,
|
||
|
})
|
||
|
.signers([accountKeypair])
|
||
|
.rpc();
|
||
|
|
||
|
let account = await program.account.floatDataAccount.fetch(
|
||
|
accountKeypair.publicKey
|
||
|
);
|
||
|
|
||
|
await program.methods
|
||
|
.update(3.0, 4.0)
|
||
|
.accounts({
|
||
|
account: accountKeypair.publicKey,
|
||
|
authority: authorityPublicKey,
|
||
|
})
|
||
|
.rpc();
|
||
|
|
||
|
account = await program.account.floatDataAccount.fetch(
|
||
|
accountKeypair.publicKey
|
||
|
);
|
||
|
|
||
|
assert.strictEqual(account.dataF32, 3.0);
|
||
|
assert.strictEqual(account.dataF64, 4.0);
|
||
|
});
|
||
|
});
|