|
1 | 1 | import * as anchor from '@coral-xyz/anchor'; |
2 | | -import { Program } from '@coral-xyz/anchor'; |
3 | | -import { AccountData } from '../target/types/account_data'; |
| 2 | +import { PublicKey } from '@solana/web3.js'; |
| 3 | +import type { AccountData } from '../target/types/account_data'; |
4 | 4 |
|
5 | | -describe('account-data', () => { |
6 | | - // Configure the client to use the local cluster. |
7 | | - anchor.setProvider(anchor.AnchorProvider.env()); |
| 5 | +describe('Account Data!', () => { |
| 6 | + const provider = anchor.AnchorProvider.env(); |
| 7 | + anchor.setProvider(provider); |
| 8 | + const payer = provider.wallet as anchor.Wallet; |
| 9 | + const program = anchor.workspace.AccountData as anchor.Program<AccountData>; |
8 | 10 |
|
9 | | - const program = anchor.workspace.AccountData as Program<AccountData>; |
| 11 | + // Generate a new keypair for the addressInfo account |
| 12 | + const [addressInfoAccount] = PublicKey.findProgramAddressSync([Buffer.from('address_info'), payer.publicKey.toBuffer()], program.programId); |
10 | 13 |
|
11 | | - it('Is initialized!', async () => { |
12 | | - // Add your test here. |
13 | | - const tx = await program.methods.initialize().rpc(); |
14 | | - console.log('Your transaction signature', tx); |
| 14 | + it('Create the address info account', async () => { |
| 15 | + console.log(`Payer Address : ${payer.publicKey}`); |
| 16 | + console.log(`Address Info Acct : ${addressInfoAccount}`); |
| 17 | + |
| 18 | + // Instruction Ix data |
| 19 | + const addressInfo = { |
| 20 | + name: 'Joe C', |
| 21 | + houseNumber: 136, |
| 22 | + street: 'Mile High Dr.', |
| 23 | + city: 'Solana Beach', |
| 24 | + }; |
| 25 | + |
| 26 | + await program.methods |
| 27 | + .createAddressInfo(addressInfo.name, addressInfo.houseNumber, addressInfo.street, addressInfo.city) |
| 28 | + .accounts({ |
| 29 | + addressInfo: addressInfoAccount, |
| 30 | + payer: payer.publicKey, |
| 31 | + }) |
| 32 | + .rpc(); |
| 33 | + }); |
| 34 | + |
| 35 | + it("Read the new account's data", async () => { |
| 36 | + const addressInfo = await program.account.addressInfo.fetch(addressInfoAccount); |
| 37 | + console.log(`Name : ${addressInfo.name}`); |
| 38 | + console.log(`House Num: ${addressInfo.houseNumber}`); |
| 39 | + console.log(`Street : ${addressInfo.street}`); |
| 40 | + console.log(`City : ${addressInfo.city}`); |
15 | 41 | }); |
16 | 42 | }); |
0 commit comments