From 456f34e95b7590639bade884a9255a29586ad1e7 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Wed, 24 Apr 2019 15:22:50 -0700 Subject: [PATCH] fix: add fullnodeExit() --- web3.js/module.flow.js | 1 + web3.js/src/connection.js | 13 +++++++++++++ web3.js/test/connection.test.js | 22 ++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/web3.js/module.flow.js b/web3.js/module.flow.js index 013d98d695..cbbe8201bb 100644 --- a/web3.js/module.flow.js +++ b/web3.js/module.flow.js @@ -98,6 +98,7 @@ declare module '@solana/web3.js' { callback: ProgramAccountChangeCallback, ): number; removeProgramAccountChangeListener(id: number): Promise; + fullnodeExit(): Promise; } // === src/system-program.js === diff --git a/web3.js/src/connection.js b/web3.js/src/connection.js index f116745d50..62544a1ea3 100644 --- a/web3.js/src/connection.js +++ b/web3.js/src/connection.js @@ -521,6 +521,19 @@ export class Connection { return await this.sendRawTransaction(wireTransaction); } + /** + * @private + */ + async fullnodeExit(): Promise { + const unsafeRes = await this._rpcRequest('fullnodeExit', []); + const res = jsonRpcResult('boolean')(unsafeRes); + if (res.error) { + throw new Error(res.error.message); + } + assert(typeof res.result !== 'undefined'); + return res.result; + } + /** * Send a transaction that has already been signed and serialized into the * wire format diff --git a/web3.js/test/connection.test.js b/web3.js/test/connection.test.js index 183f456917..bd4a5dd35f 100644 --- a/web3.js/test/connection.test.js +++ b/web3.js/test/connection.test.js @@ -44,6 +44,28 @@ test('get account info - error', () => { ); }); +test('fullnodeExit', async () => { + if (!mockRpcEnabled) { + console.log('fullnodeExit skipped on live node'); + return; + } + const connection = new Connection(url); + + mockRpc.push([ + url, + { + method: 'fullnodeExit', + }, + { + error: null, + result: false, + }, + ]); + + const result = await connection.fullnodeExit(); + expect(result).toBe(false); +}); + test('get balance', async () => { const account = new Account(); const connection = new Connection(url);