-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add feature RPC * export, add tests * update history * fix test * update models * update feature models to correctly handle both cases * fix models/tests * fix test, improve type * undo type change * fix test
- Loading branch information
Showing
4 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { BaseRequest, BaseResponse } from './baseMethod' | ||
|
||
export interface FeatureAllRequest extends BaseRequest { | ||
command: 'feature' | ||
|
||
feature?: never | ||
} | ||
|
||
export interface FeatureOneRequest extends BaseRequest { | ||
command: 'feature' | ||
|
||
feature: string | ||
} | ||
|
||
/** | ||
* The `feature` command returns information about amendments this server knows about, including whether they are enabled. | ||
* Returns an {@link FeatureResponse}. | ||
* | ||
* @category Requests | ||
*/ | ||
export type FeatureRequest = FeatureAllRequest | FeatureOneRequest | ||
|
||
export interface FeatureAllResponse extends BaseResponse { | ||
result: { | ||
features: Record< | ||
string, | ||
{ | ||
/* | ||
* Whether this amendment is currently enabled in the latest ledger. | ||
*/ | ||
enabled: boolean | ||
|
||
/* | ||
* The human-readable name for this amendment, if known. | ||
*/ | ||
name: string | ||
|
||
supported: boolean | ||
} | ||
> | ||
} | ||
} | ||
|
||
export interface FeatureOneResponse extends BaseResponse { | ||
result: Record< | ||
string, | ||
{ | ||
/* | ||
* Whether this amendment is currently enabled in the latest ledger. | ||
*/ | ||
enabled: boolean | ||
|
||
/* | ||
* The human-readable name for this amendment, if known. | ||
*/ | ||
name: string | ||
|
||
supported: boolean | ||
} | ||
> | ||
} | ||
|
||
/** | ||
* Response expected from an {@link FeatureRequest}. | ||
* | ||
* @category Responses | ||
*/ | ||
export type FeatureResponse = FeatureAllResponse | FeatureOneResponse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { assert } from 'chai' | ||
|
||
import { FeatureRequest } from '../../../src' | ||
import serverUrl from '../serverUrl' | ||
import { | ||
setupClient, | ||
teardownClient, | ||
type XrplIntegrationTestContext, | ||
} from '../setup' | ||
|
||
// how long before each test case times out | ||
const TIMEOUT = 20000 | ||
const AMENDMENT = | ||
'8CC0774A3BF66D1D22E76BBDA8E8A232E6B6313834301B3B23E8601196AE6455' | ||
|
||
describe('feature', function () { | ||
let testContext: XrplIntegrationTestContext | ||
|
||
beforeEach(async () => { | ||
testContext = await setupClient(serverUrl) | ||
}) | ||
afterEach(async () => teardownClient(testContext)) | ||
|
||
it( | ||
'all', | ||
async () => { | ||
const featureRequest: FeatureRequest = { | ||
command: 'feature', | ||
} | ||
const featureResponse = await testContext.client.request(featureRequest) | ||
|
||
assert.equal(featureResponse.type, 'response') | ||
assert.typeOf(featureResponse.result.features, 'object') | ||
assert.isTrue(AMENDMENT in featureResponse.result.features) | ||
|
||
const amendmentData = featureResponse.result.features[AMENDMENT] | ||
assert.equal(amendmentData.name, 'AMM') | ||
// TODO: rippled says "false" for standalone nodes for some reason | ||
assert.typeOf(amendmentData.enabled, 'boolean') | ||
assert.equal(amendmentData.supported, true) | ||
}, | ||
TIMEOUT, | ||
) | ||
|
||
it( | ||
'one', | ||
async () => { | ||
const featureRequest: FeatureRequest = { | ||
command: 'feature', | ||
feature: AMENDMENT, | ||
} | ||
const featureResponse = await testContext.client.request(featureRequest) | ||
|
||
assert.equal(featureResponse.type, 'response') | ||
assert.typeOf(featureResponse.result, 'object') | ||
assert.isTrue(AMENDMENT in featureResponse.result) | ||
assert.lengthOf(Object.keys(featureResponse.result), 1) | ||
|
||
const amendmentData = featureResponse.result[AMENDMENT] | ||
|
||
assert.equal(amendmentData.name, 'AMM') | ||
// TODO: rippled says "false" for standalone nodes for some reason | ||
assert.typeOf(amendmentData.enabled, 'boolean') | ||
assert.equal(amendmentData.supported, true) | ||
}, | ||
TIMEOUT, | ||
) | ||
}) |