-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
393 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
"@onflow/fcl-react-native": minor | ||
"@onflow/transport-grpc": minor | ||
"@onflow/transport-http": minor | ||
"@onflow/fcl-core": minor | ||
"@onflow/typedefs": minor | ||
"@onflow/fcl": minor | ||
"@onflow/sdk": minor | ||
--- | ||
|
||
Add GetNodeVersionInfo SDK Interaction |
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
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
10 changes: 10 additions & 0 deletions
10
packages/sdk/src/build/build-get-node-version-info.test.ts
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,10 @@ | ||
import {initInteraction, isGetNodeVersionInfo} from "../interaction/interaction" | ||
import {getNodeVersionInfo} from "./build-get-node-version-info" | ||
|
||
describe("Build Get Node Version Info", () => { | ||
test("Get Node Version Info", async () => { | ||
let ix = await getNodeVersionInfo()(initInteraction()) | ||
|
||
expect(isGetNodeVersionInfo(ix)).toBe(true) | ||
}) | ||
}) |
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,17 @@ | ||
import { Ok, makeGetNodeVerionInfo, pipe } from "../interaction/interaction" | ||
|
||
/** | ||
* @description - A builder function that returns the interaction to get a block header | ||
* @param {boolean} [isSealed] - Whether or not the block should be sealed | ||
* @returns {Function} - An interaction object | ||
*/ | ||
export function getNodeVersionInfo(isSealed = null) { | ||
return pipe([ | ||
makeGetNodeVerionInfo, | ||
ix => { | ||
ix.block.isSealed = isSealed | ||
return Ok(ix) | ||
}, | ||
]) | ||
} | ||
|
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
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,14 @@ | ||
import {send} from "../send/send.js" | ||
import {decodeResponse as decode} from "../decode/decode.js" | ||
import {getNodeVersionInfo} from "../build/build-get-node-version-info" | ||
import {NodeVersionInfo} from "@onflow/typedefs" | ||
|
||
/** | ||
* @description Returns the version information from to connected node | ||
* @returns A promise that resolves to a block response | ||
*/ | ||
export async function nodeVersionInfo( | ||
opts: any = {} | ||
): Promise<NodeVersionInfo> { | ||
return send([getNodeVersionInfo()], opts).then(decode) | ||
} |
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
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
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,39 @@ | ||
import {invariant} from "@onflow/util-invariant" | ||
import {AccessAPI, GetNodeVersionInfoRequest} from "@onflow/protobuf" | ||
import {unary as defaultUnary} from "./unary" | ||
|
||
const u8ToHex = (u8, context) => context.Buffer.from(u8).toString("hex") | ||
|
||
export async function sendGetNodeVersionInfo(ix, context = {}, opts = {}) { | ||
invariant( | ||
opts.node, | ||
`SDK Send Get Node Version Info Error: opts.node must be defined.` | ||
) | ||
invariant( | ||
context.response, | ||
`SDK Send Get Node Version INfo Error: context.response must be defined.` | ||
) | ||
|
||
const unary = opts.unary || defaultUnary | ||
|
||
ix = await ix | ||
|
||
const req = new GetNodeVersionInfoRequest() | ||
|
||
const res = await unary(opts.node, AccessAPI.GetNodeVersionInfo, req, context) | ||
|
||
let ret = context.response() | ||
ret.tag = ix.tag | ||
|
||
let nodeVersionInfo = res.getInfo() | ||
ret.nodeVersionInfo = { | ||
semver: nodeVersionInfo.getSemver(), | ||
commit: nodeVersionInfo.getCommit(), | ||
sporkId: u8ToHex(nodeVersionInfo.getSporkId_asU8(), context), | ||
protocolVersion: parseInt(nodeVersionInfo.getProtocolVersion()), | ||
sporkRootBlockHeight: parseInt(nodeVersionInfo.getSporkRootBlockHeight()), | ||
nodeRootBlockHeight: parseInt(nodeVersionInfo.getNodeRootBlockHeight()), | ||
} | ||
|
||
return ret | ||
} |
56 changes: 56 additions & 0 deletions
56
packages/transport-grpc/src/send-get-node-version-info.test.js
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,56 @@ | ||
import {AccessAPI} from "@onflow/protobuf" | ||
import {sendGetNodeVersionInfo} from "./send-get-node-version-info" | ||
import { | ||
build, | ||
getNodeVersionInfo, | ||
resolve, | ||
response as responseADT, | ||
} from "@onflow/sdk" | ||
|
||
describe("Get Network Parameters", () => { | ||
test("GetNetworkParametersResult", async () => { | ||
const unaryMock = jest.fn() | ||
|
||
unaryMock.mockReturnValue({ | ||
getInfo: () => ({ | ||
getSemver: () => "0.0.0", | ||
getCommit: () => "0123456789abcdef", | ||
getSporkId_asU8: () => new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), | ||
getProtocolVersion: () => "999", | ||
getSporkRootBlockHeight: () => "123", | ||
getNodeRootBlockHeight: () => "456", | ||
}), | ||
}) | ||
|
||
const response = await sendGetNodeVersionInfo( | ||
await resolve(await build([getNodeVersionInfo()])), | ||
{ | ||
Buffer, | ||
response: responseADT, | ||
}, | ||
{ | ||
unary: unaryMock, | ||
node: "localhost:3000", | ||
} | ||
) | ||
|
||
expect(unaryMock.mock.calls.length).toEqual(1) | ||
|
||
const unaryMockArgs = unaryMock.mock.calls[0] | ||
|
||
expect(unaryMockArgs.length).toEqual(4) | ||
|
||
const unaryType = unaryMock.mock.calls[0][1] | ||
|
||
expect(unaryType).toEqual(AccessAPI.GetNodeVersionInfo) | ||
|
||
expect(response.nodeVersionInfo).toStrictEqual({ | ||
semver: "0.0.0", | ||
commit: "0123456789abcdef", | ||
sporkId: "00010203040506070809", | ||
protocolVersion: 999, | ||
sporkRootBlockHeight: 123, | ||
nodeRootBlockHeight: 456, | ||
}) | ||
}) | ||
}) |
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
60 changes: 60 additions & 0 deletions
60
packages/transport-http/src/send-get-node-version-info.test.ts
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,60 @@ | ||
import {sendGetNodeVersionInfo} from "./send-get-node-version-info" | ||
import { | ||
build, | ||
getNodeVersionInfo, | ||
resolve, | ||
response as responseADT, | ||
} from "@onflow/sdk" | ||
|
||
describe("Get Node Version Info", () => { | ||
test("GetNodeVersionInfo", async () => { | ||
const httpRequestMock = jest.fn() | ||
|
||
const returnedNodeVersionInfo = { | ||
semver: "v0.33.11-access-register-cache", | ||
commit: "4ffc02f147654ef3a936ab1b435e00a5d5d37701", | ||
spork_id: | ||
"709530929e4968daff19c303ef1fc5f0a7649b3a1ce7d5ee5202056969524c94", | ||
protocol_version: "32", | ||
spork_root_block_height: "65264619", | ||
node_root_block_height: "65264619", | ||
} | ||
|
||
httpRequestMock.mockReturnValue(returnedNodeVersionInfo) | ||
|
||
const response = await sendGetNodeVersionInfo( | ||
await resolve(await build([getNodeVersionInfo()])), | ||
{ | ||
response: responseADT, | ||
}, | ||
{ | ||
httpRequest: httpRequestMock, | ||
node: "localhost:8888", | ||
} | ||
) | ||
|
||
expect(httpRequestMock.mock.calls.length).toEqual(1) | ||
|
||
const httpRequestMockArgs = httpRequestMock.mock.calls[0] | ||
|
||
expect(httpRequestMockArgs.length).toEqual(1) | ||
|
||
const valueSent = httpRequestMock.mock.calls[0][0] | ||
|
||
expect(valueSent).toEqual({ | ||
hostname: "localhost:8888", | ||
path: "/v1/node_version_info", | ||
method: "GET", | ||
}) | ||
|
||
expect(response.nodeVersionInfo).toStrictEqual({ | ||
semver: "v0.33.11-access-register-cache", | ||
commit: "4ffc02f147654ef3a936ab1b435e00a5d5d37701", | ||
sporkId: | ||
"709530929e4968daff19c303ef1fc5f0a7649b3a1ce7d5ee5202056969524c94", | ||
protocolVersion: 32, | ||
sporkRootBlockHeight: 65264619, | ||
nodeRootBlockHeight: 65264619, | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.