fix: catch up to account field renaming
This commit is contained in:
parent
1f7b8f417d
commit
67ccac9418
|
@ -35,8 +35,8 @@ declare module '@solana/web3.js' {
|
|||
// === src/connection.js ===
|
||||
declare export type AccountInfo = {
|
||||
executable: boolean,
|
||||
loaderProgramId: PublicKey,
|
||||
programId: PublicKey,
|
||||
loader: PublicKey,
|
||||
owner: PublicKey,
|
||||
tokens: number,
|
||||
userdata: Buffer,
|
||||
};
|
||||
|
|
|
@ -82,8 +82,8 @@ function jsonRpcResult(resultDescription: any) {
|
|||
*/
|
||||
const AccountInfoResult = struct({
|
||||
executable: 'boolean',
|
||||
loader_program_id: 'array',
|
||||
program_id: 'array',
|
||||
loader: 'array',
|
||||
owner: 'array',
|
||||
tokens: 'number',
|
||||
userdata: 'array',
|
||||
});
|
||||
|
@ -149,12 +149,15 @@ const SendTokensRpcResult = jsonRpcResult('string');
|
|||
*
|
||||
* @typedef {Object} AccountInfo
|
||||
* @property {number} tokens Number of tokens assigned to the account
|
||||
* @property {PublicKey} programId Identifier of the program assigned to the account
|
||||
* @property {PublicKey} owner Identifier of the program that owns the account
|
||||
* @property {?Buffer} userdata Optional userdata assigned to the account
|
||||
* @property {PublicKey} loader Identifier of the loader for this account
|
||||
* @property {boolean} executable `true` if this account's userdata contains a loaded program
|
||||
*/
|
||||
type AccountInfo = {
|
||||
executable: boolean,
|
||||
programId: PublicKey,
|
||||
loader: PublicKey,
|
||||
owner: PublicKey,
|
||||
tokens: number,
|
||||
userdata: Buffer,
|
||||
};
|
||||
|
@ -268,9 +271,9 @@ export class Connection {
|
|||
|
||||
return {
|
||||
executable: result.executable,
|
||||
loader: new PublicKey(result.loader),
|
||||
owner: new PublicKey(result.owner),
|
||||
tokens: result.tokens,
|
||||
programId: new PublicKey(result.program_id),
|
||||
loaderProgramId: new PublicKey(result.loader_program_id),
|
||||
userdata: Buffer.from(result.userdata),
|
||||
};
|
||||
}
|
||||
|
@ -474,9 +477,9 @@ export class Connection {
|
|||
|
||||
sub.callback({
|
||||
executable: result.executable,
|
||||
loader: new PublicKey(result.loader),
|
||||
owner: new PublicKey(result.owner),
|
||||
tokens: result.tokens,
|
||||
programId: new PublicKey(result.program_id),
|
||||
loaderProgramId: new PublicKey(result.loader_program_id),
|
||||
userdata: Buffer.from(result.userdata),
|
||||
});
|
||||
return true;
|
||||
|
|
|
@ -305,9 +305,9 @@ export class Token {
|
|||
*/
|
||||
async tokenInfo(): Promise<TokenInfo> {
|
||||
const accountInfo = await this.connection.getAccountInfo(this.token);
|
||||
if (!accountInfo.programId.equals(this.programId)) {
|
||||
if (!accountInfo.owner.equals(this.programId)) {
|
||||
throw new Error(
|
||||
`Invalid token programId: ${JSON.stringify(accountInfo.programId)}`,
|
||||
`Invalid token owner: ${JSON.stringify(accountInfo.owner)}`,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -328,8 +328,8 @@ export class Token {
|
|||
*/
|
||||
async accountInfo(account: PublicKey): Promise<TokenAccountInfo> {
|
||||
const accountInfo = await this.connection.getAccountInfo(account);
|
||||
if (!accountInfo.programId.equals(this.programId)) {
|
||||
throw new Error(`Invalid token account programId`);
|
||||
if (!accountInfo.owner.equals(this.programId)) {
|
||||
throw new Error(`Invalid token account owner`);
|
||||
}
|
||||
|
||||
const userdata = Buffer.from(accountInfo.userdata);
|
||||
|
|
|
@ -197,7 +197,7 @@ test('request airdrop', async () => {
|
|||
{
|
||||
error: null,
|
||||
result: {
|
||||
program_id: [
|
||||
owner: [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -234,7 +234,7 @@ test('request airdrop', async () => {
|
|||
tokens: 42,
|
||||
userdata: [],
|
||||
executable: false,
|
||||
loader_program_id: [
|
||||
loader: [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -275,7 +275,7 @@ test('request airdrop', async () => {
|
|||
const accountInfo = await connection.getAccountInfo(account.publicKey);
|
||||
expect(accountInfo.tokens).toBe(42);
|
||||
expect(accountInfo.userdata).toHaveLength(0);
|
||||
expect(accountInfo.programId).toEqual(SystemProgram.programId);
|
||||
expect(accountInfo.owner).toEqual(SystemProgram.programId);
|
||||
});
|
||||
|
||||
test('transaction', async () => {
|
||||
|
@ -521,7 +521,7 @@ test('account change notification', async () => {
|
|||
expect(mockCallback.mock.calls[0][0].userdata).toEqual(
|
||||
Buffer.from([0, 0, 0]),
|
||||
);
|
||||
expect(mockCallback.mock.calls[0][0].programId).toEqual(BpfLoader.programId);
|
||||
expect(mockCallback.mock.calls[0][0].owner).toEqual(BpfLoader.programId);
|
||||
|
||||
// Second mockCallback call is due to loader.load()
|
||||
expect(mockCallback.mock.calls[1][0].userdata).toEqual(
|
||||
|
|
|
@ -95,7 +95,7 @@ test('create new token', async () => {
|
|||
{
|
||||
error: null,
|
||||
result: {
|
||||
program_id: [...SYSTEM_TOKEN_PROGRAM_ID.toBuffer()],
|
||||
owner: [...SYSTEM_TOKEN_PROGRAM_ID.toBuffer()],
|
||||
tokens: 1,
|
||||
userdata: [
|
||||
1,
|
||||
|
@ -140,7 +140,7 @@ test('create new token', async () => {
|
|||
84,
|
||||
],
|
||||
executable: false,
|
||||
loader_program_id: [
|
||||
loader: [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -197,7 +197,7 @@ test('create new token', async () => {
|
|||
{
|
||||
error: null,
|
||||
result: {
|
||||
program_id: [...SYSTEM_TOKEN_PROGRAM_ID.toBuffer()],
|
||||
owner: [...SYSTEM_TOKEN_PROGRAM_ID.toBuffer()],
|
||||
tokens: 1,
|
||||
userdata: [
|
||||
2,
|
||||
|
@ -245,7 +245,7 @@ test('create new token', async () => {
|
|||
0,
|
||||
],
|
||||
executable: false,
|
||||
loader_program_id: [
|
||||
loader: [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -322,7 +322,7 @@ test('create new token account', async () => {
|
|||
{
|
||||
error: null,
|
||||
result: {
|
||||
program_id: [...SYSTEM_TOKEN_PROGRAM_ID.toBuffer()],
|
||||
owner: [...SYSTEM_TOKEN_PROGRAM_ID.toBuffer()],
|
||||
tokens: 1,
|
||||
userdata: [
|
||||
2,
|
||||
|
@ -339,7 +339,7 @@ test('create new token account', async () => {
|
|||
0,
|
||||
],
|
||||
executable: false,
|
||||
loader_program_id: [
|
||||
loader: [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -416,7 +416,7 @@ test('transfer', async () => {
|
|||
{
|
||||
error: null,
|
||||
result: {
|
||||
program_id: [...SYSTEM_TOKEN_PROGRAM_ID.toBuffer()],
|
||||
owner: [...SYSTEM_TOKEN_PROGRAM_ID.toBuffer()],
|
||||
tokens: 1,
|
||||
userdata: [
|
||||
2,
|
||||
|
@ -433,7 +433,7 @@ test('transfer', async () => {
|
|||
0,
|
||||
],
|
||||
executable: false,
|
||||
loader_program_id: [
|
||||
loader: [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -477,12 +477,7 @@ test('transfer', async () => {
|
|||
mockGetSignatureStatus();
|
||||
}
|
||||
|
||||
await testToken.transfer(
|
||||
initialOwner,
|
||||
initialOwnerTokenAccount,
|
||||
dest,
|
||||
123,
|
||||
);
|
||||
await testToken.transfer(initialOwner, initialOwnerTokenAccount, dest, 123);
|
||||
|
||||
{
|
||||
// mock Token.accountInfo()'s getAccountInfo
|
||||
|
@ -495,7 +490,7 @@ test('transfer', async () => {
|
|||
{
|
||||
error: null,
|
||||
result: {
|
||||
program_id: [...SYSTEM_TOKEN_PROGRAM_ID.toBuffer()],
|
||||
owner: [...SYSTEM_TOKEN_PROGRAM_ID.toBuffer()],
|
||||
tokens: 1,
|
||||
userdata: [
|
||||
2,
|
||||
|
@ -512,7 +507,7 @@ test('transfer', async () => {
|
|||
0,
|
||||
],
|
||||
executable: false,
|
||||
loader_program_id: [
|
||||
loader: [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -601,7 +596,7 @@ test('approve/revoke', async () => {
|
|||
{
|
||||
error: null,
|
||||
result: {
|
||||
program_id: [...SYSTEM_TOKEN_PROGRAM_ID.toBuffer()],
|
||||
owner: [...SYSTEM_TOKEN_PROGRAM_ID.toBuffer()],
|
||||
tokens: 1,
|
||||
userdata: [
|
||||
2,
|
||||
|
@ -627,7 +622,7 @@ test('approve/revoke', async () => {
|
|||
0,
|
||||
],
|
||||
executable: false,
|
||||
loader_program_id: [
|
||||
loader: [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -698,7 +693,7 @@ test('approve/revoke', async () => {
|
|||
{
|
||||
error: null,
|
||||
result: {
|
||||
program_id: [...SYSTEM_TOKEN_PROGRAM_ID.toBuffer()],
|
||||
owner: [...SYSTEM_TOKEN_PROGRAM_ID.toBuffer()],
|
||||
tokens: 1,
|
||||
userdata: [
|
||||
2,
|
||||
|
@ -724,7 +719,7 @@ test('approve/revoke', async () => {
|
|||
0,
|
||||
],
|
||||
executable: false,
|
||||
loader_program_id: [
|
||||
loader: [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
|
Loading…
Reference in New Issue