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