fix: adapt to binary64 RPC encoding change
This commit is contained in:
@ -713,7 +713,7 @@ const GetTokenAccountsByOwner = jsonRpcResultAndContext(
|
|||||||
executable: 'boolean',
|
executable: 'boolean',
|
||||||
owner: 'string',
|
owner: 'string',
|
||||||
lamports: 'number',
|
lamports: 'number',
|
||||||
data: 'string',
|
data: ['string', struct.literal('binary64')],
|
||||||
rentEpoch: 'number?',
|
rentEpoch: 'number?',
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
@ -795,7 +795,7 @@ const ParsedAccountInfoResult = struct.object({
|
|||||||
owner: 'string',
|
owner: 'string',
|
||||||
lamports: 'number',
|
lamports: 'number',
|
||||||
data: struct.union([
|
data: struct.union([
|
||||||
'string',
|
['string', struct.literal('binary64')],
|
||||||
struct.pick({
|
struct.pick({
|
||||||
program: 'string',
|
program: 'string',
|
||||||
parsed: 'any',
|
parsed: 'any',
|
||||||
@ -1631,15 +1631,18 @@ export class Connection {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
context,
|
context,
|
||||||
value: value.map(result => ({
|
value: value.map(result => {
|
||||||
|
assert(result.account.data[1] === 'binary64');
|
||||||
|
return {
|
||||||
pubkey: new PublicKey(result.pubkey),
|
pubkey: new PublicKey(result.pubkey),
|
||||||
account: {
|
account: {
|
||||||
executable: result.account.executable,
|
executable: result.account.executable,
|
||||||
owner: new PublicKey(result.account.owner),
|
owner: new PublicKey(result.account.owner),
|
||||||
lamports: result.account.lamports,
|
lamports: result.account.lamports,
|
||||||
data: Buffer.from(result.account.data, 'base64'),
|
data: Buffer.from(result.account.data[0], 'base64'),
|
||||||
},
|
},
|
||||||
})),
|
};
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1769,11 +1772,12 @@ export class Connection {
|
|||||||
let value = null;
|
let value = null;
|
||||||
if (res.result.value) {
|
if (res.result.value) {
|
||||||
const {executable, owner, lamports, data} = res.result.value;
|
const {executable, owner, lamports, data} = res.result.value;
|
||||||
|
assert(data[1] === 'binary64');
|
||||||
value = {
|
value = {
|
||||||
executable,
|
executable,
|
||||||
owner: new PublicKey(owner),
|
owner: new PublicKey(owner),
|
||||||
lamports,
|
lamports,
|
||||||
data: Buffer.from(data, 'base64'),
|
data: Buffer.from(data[0], 'base64'),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1817,7 +1821,8 @@ export class Connection {
|
|||||||
|
|
||||||
let data = resultData;
|
let data = resultData;
|
||||||
if (!data.program) {
|
if (!data.program) {
|
||||||
data = Buffer.from(data, 'base64');
|
assert(data[1] === 'binary64');
|
||||||
|
data = Buffer.from(data[0], 'base64');
|
||||||
}
|
}
|
||||||
|
|
||||||
value = {
|
value = {
|
||||||
@ -1881,13 +1886,14 @@ export class Connection {
|
|||||||
assert(typeof result !== 'undefined');
|
assert(typeof result !== 'undefined');
|
||||||
|
|
||||||
return result.map(result => {
|
return result.map(result => {
|
||||||
|
assert(result.account.data[1] === 'binary64');
|
||||||
return {
|
return {
|
||||||
pubkey: new PublicKey(result.pubkey),
|
pubkey: new PublicKey(result.pubkey),
|
||||||
account: {
|
account: {
|
||||||
executable: result.account.executable,
|
executable: result.account.executable,
|
||||||
owner: new PublicKey(result.account.owner),
|
owner: new PublicKey(result.account.owner),
|
||||||
lamports: result.account.lamports,
|
lamports: result.account.lamports,
|
||||||
data: Buffer.from(result.account.data, 'base64'),
|
data: Buffer.from(result.account.data[0], 'base64'),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@ -1931,7 +1937,8 @@ export class Connection {
|
|||||||
|
|
||||||
let data = resultData;
|
let data = resultData;
|
||||||
if (!data.program) {
|
if (!data.program) {
|
||||||
data = Buffer.from(data, 'base64');
|
assert(data[1] === 'binary64');
|
||||||
|
data = Buffer.from(data[0], 'base64');
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -2899,6 +2906,7 @@ export class Connection {
|
|||||||
const {result} = res;
|
const {result} = res;
|
||||||
const {value, context} = result;
|
const {value, context} = result;
|
||||||
|
|
||||||
|
assert(value.account.data[1] === 'binary64');
|
||||||
sub.callback(
|
sub.callback(
|
||||||
{
|
{
|
||||||
accountId: value.pubkey,
|
accountId: value.pubkey,
|
||||||
@ -2906,7 +2914,7 @@ export class Connection {
|
|||||||
executable: value.account.executable,
|
executable: value.account.executable,
|
||||||
owner: new PublicKey(value.account.owner),
|
owner: new PublicKey(value.account.owner),
|
||||||
lamports: value.account.lamports,
|
lamports: value.account.lamports,
|
||||||
data: Buffer.from(value.account.data, 'base64'),
|
data: Buffer.from(value.account.data[0], 'base64'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
context,
|
context,
|
||||||
|
@ -263,7 +263,7 @@ test('get program accounts', async () => {
|
|||||||
result: [
|
result: [
|
||||||
{
|
{
|
||||||
account: {
|
account: {
|
||||||
data: '',
|
data: ['', 'binary64'],
|
||||||
executable: false,
|
executable: false,
|
||||||
lamports: LAMPORTS_PER_SOL - feeCalculator.lamportsPerSignature,
|
lamports: LAMPORTS_PER_SOL - feeCalculator.lamportsPerSignature,
|
||||||
owner: programId.publicKey.toBase58(),
|
owner: programId.publicKey.toBase58(),
|
||||||
@ -273,7 +273,7 @@ test('get program accounts', async () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
account: {
|
account: {
|
||||||
data: '',
|
data: ['', 'binary64'],
|
||||||
executable: false,
|
executable: false,
|
||||||
lamports:
|
lamports:
|
||||||
0.5 * LAMPORTS_PER_SOL - feeCalculator.lamportsPerSignature,
|
0.5 * LAMPORTS_PER_SOL - feeCalculator.lamportsPerSignature,
|
||||||
@ -1693,7 +1693,7 @@ test('request airdrop', async () => {
|
|||||||
value: {
|
value: {
|
||||||
owner: '11111111111111111111111111111111',
|
owner: '11111111111111111111111111111111',
|
||||||
lamports: minimumAmount + 42,
|
lamports: minimumAmount + 42,
|
||||||
data: '',
|
data: ['', 'binary64'],
|
||||||
executable: false,
|
executable: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1727,7 +1727,7 @@ test('request airdrop', async () => {
|
|||||||
value: {
|
value: {
|
||||||
owner: '11111111111111111111111111111111',
|
owner: '11111111111111111111111111111111',
|
||||||
lamports: minimumAmount + 42,
|
lamports: minimumAmount + 42,
|
||||||
data: '',
|
data: ['', 'binary64'],
|
||||||
executable: false,
|
executable: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -14,7 +14,7 @@ if (!mockRpcEnabled) {
|
|||||||
jest.setTimeout(30000);
|
jest.setTimeout(30000);
|
||||||
}
|
}
|
||||||
|
|
||||||
const expectedData = (authorizedPubkey: PublicKey): string => {
|
const expectedData = (authorizedPubkey: PublicKey): [string, string] => {
|
||||||
const expectedData = Buffer.alloc(NONCE_ACCOUNT_LENGTH);
|
const expectedData = Buffer.alloc(NONCE_ACCOUNT_LENGTH);
|
||||||
expectedData.writeInt32LE(0, 0); // Version, 4 bytes
|
expectedData.writeInt32LE(0, 0); // Version, 4 bytes
|
||||||
expectedData.writeInt32LE(1, 4); // State, 4 bytes
|
expectedData.writeInt32LE(1, 4); // State, 4 bytes
|
||||||
@ -22,7 +22,7 @@ const expectedData = (authorizedPubkey: PublicKey): string => {
|
|||||||
const mockNonce = new Account();
|
const mockNonce = new Account();
|
||||||
mockNonce.publicKey.toBuffer().copy(expectedData, 40); // Hash, 32 bytes
|
mockNonce.publicKey.toBuffer().copy(expectedData, 40); // Hash, 32 bytes
|
||||||
expectedData.writeUInt16LE(5000, 72); // feeCalculator, 8 bytes
|
expectedData.writeUInt16LE(5000, 72); // feeCalculator, 8 bytes
|
||||||
return expectedData.toString('base64');
|
return [expectedData.toString('base64'), 'binary64'];
|
||||||
};
|
};
|
||||||
|
|
||||||
test('create and query nonce account', async () => {
|
test('create and query nonce account', async () => {
|
||||||
@ -119,7 +119,10 @@ test('create and query nonce account', async () => {
|
|||||||
url,
|
url,
|
||||||
{
|
{
|
||||||
method: 'getAccountInfo',
|
method: 'getAccountInfo',
|
||||||
params: [nonceAccount.publicKey.toBase58(), {commitment: 'recent'}],
|
params: [
|
||||||
|
nonceAccount.publicKey.toBase58(),
|
||||||
|
{encoding: 'binary64', commitment: 'recent'},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
error: null,
|
error: null,
|
||||||
@ -243,7 +246,10 @@ test('create and query nonce account with seed', async () => {
|
|||||||
url,
|
url,
|
||||||
{
|
{
|
||||||
method: 'getAccountInfo',
|
method: 'getAccountInfo',
|
||||||
params: [noncePubkey.toBase58(), {commitment: 'recent'}],
|
params: [
|
||||||
|
noncePubkey.toBase58(),
|
||||||
|
{encoding: 'binary64', commitment: 'recent'},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
error: null,
|
error: null,
|
||||||
|
Reference in New Issue
Block a user