2021-01-14 15:16:27 -08:00
|
|
|
const assert = require("assert");
|
|
|
|
const anchor = require("@project-serum/anchor");
|
2021-09-02 16:29:25 -07:00
|
|
|
const { SystemProgram } = anchor.web3;
|
2021-01-14 15:16:27 -08:00
|
|
|
|
|
|
|
describe("basic-3", () => {
|
|
|
|
const provider = anchor.Provider.local();
|
|
|
|
|
|
|
|
// Configure the client to use the local cluster.
|
|
|
|
anchor.setProvider(provider);
|
|
|
|
|
|
|
|
it("Performs CPI from puppet master to puppet", async () => {
|
|
|
|
const puppetMaster = anchor.workspace.PuppetMaster;
|
|
|
|
const puppet = anchor.workspace.Puppet;
|
|
|
|
|
|
|
|
// Initialize a new puppet account.
|
2021-05-15 14:43:25 -07:00
|
|
|
const newPuppetAccount = anchor.web3.Keypair.generate();
|
2021-01-14 15:16:27 -08:00
|
|
|
const tx = await puppet.rpc.initialize({
|
|
|
|
accounts: {
|
|
|
|
puppet: newPuppetAccount.publicKey,
|
2021-09-02 16:29:25 -07:00
|
|
|
user: provider.wallet.publicKey,
|
|
|
|
systemProgram: SystemProgram.programId,
|
2021-01-14 15:16:27 -08:00
|
|
|
},
|
|
|
|
signers: [newPuppetAccount],
|
|
|
|
});
|
|
|
|
|
|
|
|
// Invoke the puppet master to perform a CPI to the puppet.
|
|
|
|
await puppetMaster.rpc.pullStrings(new anchor.BN(111), {
|
2021-12-15 15:11:41 -08:00
|
|
|
accounts: {
|
|
|
|
puppet: newPuppetAccount.publicKey,
|
|
|
|
puppetProgram: puppet.programId,
|
|
|
|
},
|
2021-01-14 15:16:27 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
// Check the state updated.
|
2021-09-11 14:43:12 -07:00
|
|
|
puppetAccount = await puppet.account.data.fetch(newPuppetAccount.publicKey);
|
2021-01-14 15:16:27 -08:00
|
|
|
assert.ok(puppetAccount.data.eq(new anchor.BN(111)));
|
|
|
|
});
|
|
|
|
});
|