Skip to content

Commit

Permalink
Add missing space attribute to accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
lorisleiva committed Nov 15, 2024
1 parent 2ee3257 commit c1bb77a
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/nervous-emus-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@solana/rpc-types': patch
'@solana/accounts': patch
---

Add missing `space` attribute to `AccountInfoBase` and `BaseAccount`
3 changes: 3 additions & 0 deletions packages/accounts/src/__tests__/decode-account-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('decodeAccount', () => {
executable: false,
lamports: 1_000_000_000n,
programAddress: '9999',
space: 3n,
};

// And a mock decoder.
Expand All @@ -37,6 +38,7 @@ describe('decodeAccount', () => {
executable: false,
lamports: 1_000_000_000n,
programAddress: '9999',
space: 3n,
});

// And the decoder to have been called with the encoded account data.
Expand All @@ -51,6 +53,7 @@ describe('decodeAccount', () => {
executable: false,
lamports: 1_000_000_000n,
programAddress: '9999',
space: 3n,
};

// And a mock decoder.
Expand Down
14 changes: 12 additions & 2 deletions packages/accounts/src/__tests__/fetch-account-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('fetchEncodedAccount', () => {
executable: false,
lamports: 1_000_000_000n,
owner: '9999',
space: 6n,
},
});

Expand All @@ -38,6 +39,7 @@ describe('fetchEncodedAccount', () => {
exists: true,
lamports: 1_000_000_000n,
programAddress: '9999',
space: 6n,
});

// And the getAccountInfo RPC method to have been called with the given address and an explicit base64 encoding.
Expand Down Expand Up @@ -73,6 +75,7 @@ describe('fetchEncodedAccount', () => {
executable: false,
lamports: 1_000_000_000n,
owner: '9999',
space: 6n,
},
});

Expand All @@ -98,11 +101,12 @@ describe('fetchJsonParsedAccount', () => {
type: 'token',
},
program: 'splToken',
space: 165n,
space: 165n, // The space field is provided again on some JSON-parsed RPC response.
},
executable: false,
lamports: 1_000_000_000n,
owner: '9999',
space: 165n,
},
});

Expand All @@ -119,6 +123,7 @@ describe('fetchJsonParsedAccount', () => {
exists: true,
lamports: 1_000_000_000n,
programAddress: '9999',
space: 165n,
});

// And the getAccountInfo RPC method to have been called with the given address and an explicit jsonParsed encoding.
Expand Down Expand Up @@ -188,6 +193,7 @@ describe('fetchEncodedAccounts', () => {
executable: false,
lamports: 1_000_000_000n,
owner: '9999',
space: 6n,
},
});

Expand All @@ -206,6 +212,7 @@ describe('fetchEncodedAccounts', () => {
exists: true,
lamports: 1_000_000_000n,
programAddress: '9999',
space: 6n,
});

// And account B is returned as a non-existing account.
Expand All @@ -229,6 +236,7 @@ describe('fetchEncodedAccounts', () => {
executable: false,
lamports: 1_000_000_000n,
owner: '9999',
space: 6n,
},
});

Expand Down Expand Up @@ -258,11 +266,12 @@ describe('fetchJsonParsedAccounts', () => {
type: 'token',
},
program: 'splToken',
space: 165n,
space: 165n, // The space field is provided again on some JSON-parsed RPC response.
},
executable: false,
lamports: 1_000_000_000n,
owner: '9999',
space: 165n,
},
});

Expand All @@ -282,6 +291,7 @@ describe('fetchJsonParsedAccounts', () => {
exists: true,
lamports: 1_000_000_000n,
programAddress: '9999',
space: 165n,
});

// And account B is returned as a non-existing account.
Expand Down
15 changes: 13 additions & 2 deletions packages/accounts/src/__tests__/parse-account-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('parseBase64RpcAccount', () => {
executable: false,
lamports: 1_000_000_000n,
owner: '9999',
space: 6n,
};

// When we parse that RPC account using the parseBase64RpcAccount function.
Expand All @@ -33,6 +34,7 @@ describe('parseBase64RpcAccount', () => {
exists: true,
lamports: 1_000_000_000n,
programAddress: '9999',
space: 6n,
});
});

Expand All @@ -58,6 +60,7 @@ describe('parseBase64RpcAccount', () => {
executable: false,
lamports: 1_000_000_000n,
owner: '9999',
space: 6n,
};

// When we parse that RPC account using the parseBase64RpcAccount function.
Expand Down Expand Up @@ -88,6 +91,7 @@ describe('parseBase58RpcAccount', () => {
executable: false,
lamports: 1_000_000_000n,
owner: '9999',
space: 6n,
};

// When we parse that RPC account using the parseBase58RpcAccount function.
Expand All @@ -104,6 +108,7 @@ describe('parseBase58RpcAccount', () => {
exists: true,
lamports: 1_000_000_000n,
programAddress: '9999',
space: 6n,
});
});

Expand All @@ -115,6 +120,7 @@ describe('parseBase58RpcAccount', () => {
executable: false,
lamports: 1_000_000_000n,
owner: '9999',
space: 6n,
};

// When we parse that RPC account using the parseBase58RpcAccount function.
Expand All @@ -131,6 +137,7 @@ describe('parseBase58RpcAccount', () => {
exists: true,
lamports: 1_000_000_000n,
programAddress: '9999',
space: 6n,
});
});

Expand All @@ -156,6 +163,7 @@ describe('parseBase58RpcAccount', () => {
executable: false,
lamports: 1_000_000_000n,
owner: '9999',
space: 6n,
};

// When we parse that RPC account using the parseBase58RpcAccount function.
Expand Down Expand Up @@ -188,11 +196,12 @@ describe('parseJsonRpcAccount', () => {
type: 'token',
},
program: 'splToken',
space: 165n,
space: 165n, // The space field is provided again on some JSON-parsed RPC response.
},
executable: false,
lamports: 1_000_000_000n,
owner: '9999',
space: 165n,
};

// When we parse that RPC account using the parseJsonRpcAccount function and a custom data type.
Expand All @@ -210,6 +219,7 @@ describe('parseJsonRpcAccount', () => {
exists: true,
lamports: lamports(1_000_000_000n),
programAddress: '9999' as Address<'9999'>,
space: 165n,
} as Account<MyData>);
});

Expand Down Expand Up @@ -238,11 +248,12 @@ describe('parseJsonRpcAccount', () => {
type: 'token',
},
program: 'splToken',
space: 165n,
space: 165n, // The space field is provided again on some JSON-parsed RPC response.
},
executable: false,
lamports: 1_000_000_000n,
owner: '9999',
space: 165n,
};

// When we parse that RPC account using the parseJsonRpcAccount function.
Expand Down
1 change: 1 addition & 0 deletions packages/accounts/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type BaseAccount = {
readonly executable: boolean;
readonly lamports: Lamports;
readonly programAddress: Address;
readonly space: bigint;
};

/** Defines a Solana account with its generic details and parsed or encoded data. */
Expand Down
1 change: 1 addition & 0 deletions packages/accounts/src/parse-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@ function parseBaseAccount(rpcAccount: AccountInfoBase): BaseAccount {
executable: rpcAccount.executable,
lamports: rpcAccount.lamports,
programAddress: rpcAccount.owner,
space: rpcAccount.space,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ describe('decompileTransactionMessageFetchingLookupTables', () => {
exists: true,
lamports: 0n as Lamports,
programAddress: 'program' as Address,
space: 0n,
},
{
address: lookupTableAddress2,
Expand All @@ -279,6 +280,7 @@ describe('decompileTransactionMessageFetchingLookupTables', () => {
exists: true,
lamports: 0n as Lamports,
programAddress: 'program' as Address,
space: 0n,
},
];

Expand Down
2 changes: 2 additions & 0 deletions packages/rpc-types/src/account-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export type AccountInfoBase = Readonly<{
owner: Address;
/** the epoch at which this account will next owe rent */
rentEpoch: bigint;
/** the size of the account data in bytes (excluding the 128 bytes of header) */
space: bigint;
}>;

/** @deprecated */
Expand Down

0 comments on commit c1bb77a

Please sign in to comment.