ts: Add support for u16 (#255)
This commit is contained in:
parent
7931090898
commit
851720eb0f
|
@ -14,6 +14,7 @@ incremented for features.
|
|||
## Features
|
||||
|
||||
* client: Adds support for state instructions ([#248](https://github.com/project-serum/anchor/pull/248)).
|
||||
* ts: Add support for u16 ([#255](https://github.com/project-serum/anchor/pull/255)).
|
||||
|
||||
## Breaking
|
||||
|
||||
|
|
|
@ -52,6 +52,11 @@ pub mod misc {
|
|||
ctx.accounts.my_account.data = data;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn test_u16(ctx: Context<TestU16>, data: u16) -> ProgramResult {
|
||||
ctx.accounts.my_account.data = data;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Accounts)]
|
||||
|
@ -108,6 +113,13 @@ pub struct TestAssociatedAccount<'info> {
|
|||
system_program: AccountInfo<'info>,
|
||||
}
|
||||
|
||||
#[derive(Accounts)]
|
||||
pub struct TestU16<'info> {
|
||||
#[account(init)]
|
||||
my_account: ProgramAccount<'info, DataU16>,
|
||||
rent: Sysvar<'info, Rent>,
|
||||
}
|
||||
|
||||
#[associated]
|
||||
pub struct TestData {
|
||||
data: u64,
|
||||
|
@ -118,3 +130,8 @@ pub struct Data {
|
|||
udata: u128,
|
||||
idata: i128,
|
||||
}
|
||||
|
||||
#[account]
|
||||
pub struct DataU16 {
|
||||
data: u16,
|
||||
}
|
||||
|
|
|
@ -37,6 +37,20 @@ describe("misc", () => {
|
|||
assert.ok(dataAccount.idata.eq(new anchor.BN(22)));
|
||||
});
|
||||
|
||||
it("Can use u16", async () => {
|
||||
const data = new anchor.web3.Account();
|
||||
const tx = await program.rpc.testU16(99, {
|
||||
accounts: {
|
||||
myAccount: data.publicKey,
|
||||
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
|
||||
},
|
||||
signers: [data],
|
||||
instructions: [await program.account.dataU16.createInstruction(data)],
|
||||
});
|
||||
const dataAccount = await program.account.dataU16(data.publicKey);
|
||||
assert.ok(dataAccount.data === 99);
|
||||
});
|
||||
|
||||
it("Can embed programs into genesis from the Anchor.toml", async () => {
|
||||
const pid = new anchor.web3.PublicKey(
|
||||
"FtMNMKp9DZHKWUyVAsj3Q5QV8ow4P3fUPP7ZrWEQJzKr"
|
||||
|
@ -155,7 +169,7 @@ describe("misc", () => {
|
|||
const account = await program.account.testData.associated(
|
||||
program.provider.wallet.publicKey,
|
||||
state,
|
||||
data.publicKey,
|
||||
data.publicKey
|
||||
);
|
||||
assert.ok(account.data.toNumber() === 1234);
|
||||
});
|
||||
|
|
|
@ -285,6 +285,9 @@ class IdlCoder {
|
|||
case "u8": {
|
||||
return borsh.u8(fieldName);
|
||||
}
|
||||
case "u16": {
|
||||
return borsh.u16(fieldName);
|
||||
}
|
||||
case "u32": {
|
||||
return borsh.u32(fieldName);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue