fix anchor-lang import in safety-check, add custom-coder to ci, and fix spl-token coder (#1604)
This commit is contained in:
parent
7f8ca97aa8
commit
94b0fec714
|
@ -319,6 +319,8 @@ jobs:
|
|||
path: tests/floats
|
||||
- cmd: cd tests/safety-checks && ./test.sh
|
||||
path: tests/safety-checks
|
||||
- cmd: cd tests/custom-coder && anchor test --skip-lint
|
||||
path: tests/custom-coder
|
||||
- cmd: cd tests/validator-clone && yarn && anchor test --skip-lint
|
||||
path: tests/validator-clone
|
||||
steps:
|
||||
|
|
|
@ -30,7 +30,7 @@ incremented for features.
|
|||
* client: Fix `Cluster`'s `FromStr` implementation ([#1362](https://github.com/project-serum/anchor/pull/1362)).
|
||||
* lang: implement `Key` for `Pubkey` again, so `associated_token::*` constraints can use pubkey targets again ([#1601](https://github.com/project-serum/anchor/pull/1601)).
|
||||
* lang: adjust error code so `#[error_code]` works with just importing `anchor_lang::error_code` ([#1610](https://github.com/project-serum/anchor/pull/1610)).
|
||||
* cli/ts: generated `IDL` variable in `types/<project-name.ts>` should equal the `<project-name>.json` idl file ([#1609](https://github.com/project-serum/anchor/pull/1609))
|
||||
* ts: fix `spl-token` coder account parsing ([#1604](https://github.com/project-serum/anchor/pull/1604)).
|
||||
|
||||
### Breaking
|
||||
|
||||
|
|
|
@ -29,19 +29,20 @@ token = "{}"
|
|||
}
|
||||
|
||||
pub fn idl_ts(idl: &Idl) -> Result<String> {
|
||||
let mut idl_types = idl.clone();
|
||||
for acc in idl_types.accounts.iter_mut() {
|
||||
let mut idl = idl.clone();
|
||||
for acc in idl.accounts.iter_mut() {
|
||||
acc.name = acc.name.to_mixed_case();
|
||||
}
|
||||
let idl_json = serde_json::to_string_pretty(&idl)?;
|
||||
Ok(format!(
|
||||
r#"export type {} = {};
|
||||
|
||||
export const IDL: {} = {};
|
||||
"#,
|
||||
idl_types.name.to_camel_case(),
|
||||
serde_json::to_string_pretty(&idl_types)?,
|
||||
idl.name.to_camel_case(),
|
||||
serde_json::to_string_pretty(&idl)?
|
||||
idl_json,
|
||||
idl.name.to_camel_case(),
|
||||
idl_json
|
||||
))
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ describe("custom-coder", () => {
|
|||
assert.ok(token.mint.equals(mintKeypair.publicKey));
|
||||
assert.ok(token.amount.toNumber() === 0);
|
||||
assert.ok(token.delegate === null);
|
||||
assert.ok(token.state === 0);
|
||||
assert.ok(token.state === 1);
|
||||
assert.ok(token.isNative === null);
|
||||
assert.ok(token.delegatedAmount.toNumber() === 0);
|
||||
assert.ok(token.closeAuthority === null);
|
||||
|
|
|
@ -16,4 +16,4 @@ cpi = ["no-entrypoint"]
|
|||
default = []
|
||||
|
||||
[dependencies]
|
||||
anchor-lang = "0.22.1"
|
||||
anchor-lang = { path = "../../../../lang" }
|
||||
|
|
|
@ -10,12 +10,12 @@ export class SplTokenAccountsCoder<A extends string = string>
|
|||
|
||||
public async encode<T = any>(accountName: A, account: T): Promise<Buffer> {
|
||||
switch (accountName) {
|
||||
case "Token": {
|
||||
case "token": {
|
||||
const buffer = Buffer.alloc(165);
|
||||
const len = TOKEN_ACCOUNT_LAYOUT.encode(account, buffer);
|
||||
return buffer.slice(0, len);
|
||||
}
|
||||
case "Mint": {
|
||||
case "mint": {
|
||||
const buffer = Buffer.alloc(82);
|
||||
const len = MINT_ACCOUNT_LAYOUT.encode(account, buffer);
|
||||
return buffer.slice(0, len);
|
||||
|
@ -32,10 +32,10 @@ export class SplTokenAccountsCoder<A extends string = string>
|
|||
|
||||
public decodeUnchecked<T = any>(accountName: A, ix: Buffer): T {
|
||||
switch (accountName) {
|
||||
case "Token": {
|
||||
case "token": {
|
||||
return decodeTokenAccount(ix);
|
||||
}
|
||||
case "Mint": {
|
||||
case "mint": {
|
||||
return decodeMintAccount(ix);
|
||||
}
|
||||
default: {
|
||||
|
@ -47,12 +47,12 @@ export class SplTokenAccountsCoder<A extends string = string>
|
|||
// TODO: this won't use the appendData.
|
||||
public memcmp(accountName: A, _appendData?: Buffer): any {
|
||||
switch (accountName) {
|
||||
case "Token": {
|
||||
case "token": {
|
||||
return {
|
||||
dataSize: 165,
|
||||
};
|
||||
}
|
||||
case "Mint": {
|
||||
case "mint": {
|
||||
return {
|
||||
dataSize: 82,
|
||||
};
|
||||
|
|
|
@ -237,7 +237,7 @@ export class AccountStore<IDL extends Idl> {
|
|||
if (accountInfo === null) {
|
||||
throw new Error(`invalid account info for ${address}`);
|
||||
}
|
||||
const data = coder().accounts.decode("Token", accountInfo.data);
|
||||
const data = coder().accounts.decode("token", accountInfo.data);
|
||||
this._cache.set(address, data);
|
||||
} else {
|
||||
const account = this._accounts[camelCase(name)].fetch(publicKey);
|
||||
|
|
Loading…
Reference in New Issue