@midnightntwrk/wallet-sdk-indexer-client 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -0
- package/dist/effect/Backpressure.d.ts +97 -0
- package/dist/effect/Backpressure.js +146 -0
- package/dist/effect/ConnectionHelper.d.ts +4 -0
- package/dist/effect/ConnectionHelper.js +41 -0
- package/dist/effect/HttpQueryClient.d.ts +4 -0
- package/dist/effect/HttpQueryClient.js +50 -0
- package/dist/effect/Query.d.ts +39 -0
- package/dist/effect/Query.js +47 -0
- package/dist/effect/QueryClient.d.ts +15 -0
- package/dist/effect/QueryClient.js +15 -0
- package/dist/effect/QueryRunner.d.ts +11 -0
- package/dist/effect/QueryRunner.js +23 -0
- package/dist/effect/Subscription.d.ts +25 -0
- package/dist/effect/Subscription.js +56 -0
- package/dist/effect/SubscriptionClient.d.ts +23 -0
- package/dist/effect/SubscriptionClient.js +15 -0
- package/dist/effect/WsSubscriptionClient.d.ts +4 -0
- package/dist/effect/WsSubscriptionClient.js +89 -0
- package/dist/effect/index.d.ts +8 -0
- package/dist/effect/index.js +20 -0
- package/dist/effect/test/backpressure.test.d.ts +1 -0
- package/dist/effect/test/backpressure.test.js +146 -0
- package/dist/effect/test/connectionHelper.test.d.ts +1 -0
- package/dist/effect/test/connectionHelper.test.js +34 -0
- package/dist/effect/test/httpQueryClient.spied.test.d.ts +1 -0
- package/dist/effect/test/httpQueryClient.spied.test.js +37 -0
- package/dist/effect/test/httpQueryClient.test.d.ts +1 -0
- package/dist/effect/test/httpQueryClient.test.js +32 -0
- package/dist/effect/test/queryRunner.spied.test.d.ts +1 -0
- package/dist/effect/test/queryRunner.spied.test.js +46 -0
- package/dist/effect/test/wsSubscriptionClient.spied.test.d.ts +1 -0
- package/dist/effect/test/wsSubscriptionClient.spied.test.js +37 -0
- package/dist/effect/test/wsSubscriptionClient.test.d.ts +1 -0
- package/dist/effect/test/wsSubscriptionClient.test.js +32 -0
- package/dist/graphql/generated/fragment-masking.d.ts +19 -0
- package/dist/graphql/generated/fragment-masking.js +16 -0
- package/dist/graphql/generated/gql.d.ts +61 -0
- package/dist/graphql/generated/gql.js +17 -0
- package/dist/graphql/generated/graphql.d.ts +1021 -0
- package/dist/graphql/generated/graphql.js +700 -0
- package/dist/graphql/generated/index.d.ts +2 -0
- package/dist/graphql/generated/index.js +2 -0
- package/dist/graphql/queries/BlockHash.d.ts +6 -0
- package/dist/graphql/queries/BlockHash.js +24 -0
- package/dist/graphql/queries/Connect.d.ts +6 -0
- package/dist/graphql/queries/Connect.js +19 -0
- package/dist/graphql/queries/Disconnect.d.ts +6 -0
- package/dist/graphql/queries/Disconnect.js +19 -0
- package/dist/graphql/queries/FetchTermsAndConditions.d.ts +6 -0
- package/dist/graphql/queries/FetchTermsAndConditions.js +26 -0
- package/dist/graphql/queries/TransactionHistoryDetail.d.ts +6 -0
- package/dist/graphql/queries/TransactionHistoryDetail.js +30 -0
- package/dist/graphql/queries/TransactionStatus.d.ts +6 -0
- package/dist/graphql/queries/TransactionStatus.js +34 -0
- package/dist/graphql/queries/index.d.ts +6 -0
- package/dist/graphql/queries/index.js +18 -0
- package/dist/graphql/queries/test/BlockHash.test.d.ts +1 -0
- package/dist/graphql/queries/test/BlockHash.test.js +84 -0
- package/dist/graphql/subscriptions/DustLedgerEvents.d.ts +6 -0
- package/dist/graphql/subscriptions/DustLedgerEvents.js +24 -0
- package/dist/graphql/subscriptions/ShieldedTransactions.d.ts +8 -0
- package/dist/graphql/subscriptions/ShieldedTransactions.js +54 -0
- package/dist/graphql/subscriptions/UnshieldedTransactions.d.ts +8 -0
- package/dist/graphql/subscriptions/UnshieldedTransactions.js +68 -0
- package/dist/graphql/subscriptions/ZswapEvents.d.ts +6 -0
- package/dist/graphql/subscriptions/ZswapEvents.js +24 -0
- package/dist/graphql/subscriptions/index.d.ts +4 -0
- package/dist/graphql/subscriptions/index.js +16 -0
- package/dist/graphql/subscriptions/test/ShieldedTransactions.test.d.ts +1 -0
- package/dist/graphql/subscriptions/test/ShieldedTransactions.test.js +55 -0
- package/dist/graphql/subscriptions/test/UnshieldedTransactions.test.d.ts +1 -0
- package/dist/graphql/subscriptions/test/UnshieldedTransactions.test.js +52 -0
- package/dist/graphql/subscriptions/test/ZswapEvents.test.d.ts +1 -0
- package/dist/graphql/subscriptions/test/ZswapEvents.test.js +50 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +15 -0
- package/package.json +57 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Query } from '../../effect/index.js';
|
|
2
|
+
export declare const BlockHash: Query.Query<import("../generated/graphql.js").BlockHashQuery, import("../generated/graphql.js").Exact<{
|
|
3
|
+
offset: import("../generated/graphql.js").InputMaybe<import("../generated/graphql.js").BlockOffset>;
|
|
4
|
+
}>, Query.Query.QueryFn<import("../generated/graphql.js").BlockHashQuery, import("../generated/graphql.js").Exact<{
|
|
5
|
+
offset: import("../generated/graphql.js").InputMaybe<import("../generated/graphql.js").BlockOffset>;
|
|
6
|
+
}>>>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// This file is part of MIDNIGHT-WALLET-SDK.
|
|
2
|
+
// Copyright (C) Midnight Foundation
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// You may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { Query } from '../../effect/index.js';
|
|
14
|
+
import { gql } from '../generated/index.js';
|
|
15
|
+
export const BlockHash = Query.make('BlockHash', gql(`
|
|
16
|
+
query BlockHash($offset: BlockOffset) {
|
|
17
|
+
block(offset: $offset) {
|
|
18
|
+
height
|
|
19
|
+
hash
|
|
20
|
+
ledgerParameters
|
|
21
|
+
timestamp
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
`));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Query } from '../../effect/index.js';
|
|
2
|
+
export declare const Connect: Query.Query<import("../generated/graphql.js").ConnectMutation, import("../generated/graphql.js").Exact<{
|
|
3
|
+
viewingKey: import("../generated/graphql.js").Scalars["ViewingKey"]["input"];
|
|
4
|
+
}>, Query.Query.QueryFn<import("../generated/graphql.js").ConnectMutation, import("../generated/graphql.js").Exact<{
|
|
5
|
+
viewingKey: import("../generated/graphql.js").Scalars["ViewingKey"]["input"];
|
|
6
|
+
}>>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// This file is part of MIDNIGHT-WALLET-SDK.
|
|
2
|
+
// Copyright (C) Midnight Foundation
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// You may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { Query } from '../../effect/index.js';
|
|
14
|
+
import { gql } from '../generated/index.js';
|
|
15
|
+
export const Connect = Query.make('Connect', gql(`
|
|
16
|
+
mutation Connect($viewingKey: ViewingKey!) {
|
|
17
|
+
connect(viewingKey: $viewingKey)
|
|
18
|
+
}
|
|
19
|
+
`));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Query } from '../../effect/index.js';
|
|
2
|
+
export declare const Disconnect: Query.Query<import("../generated/graphql.js").DisconnectMutation, import("../generated/graphql.js").Exact<{
|
|
3
|
+
sessionId: import("../generated/graphql.js").Scalars["HexEncoded"]["input"];
|
|
4
|
+
}>, Query.Query.QueryFn<import("../generated/graphql.js").DisconnectMutation, import("../generated/graphql.js").Exact<{
|
|
5
|
+
sessionId: import("../generated/graphql.js").Scalars["HexEncoded"]["input"];
|
|
6
|
+
}>>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// This file is part of MIDNIGHT-WALLET-SDK.
|
|
2
|
+
// Copyright (C) Midnight Foundation
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// You may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { Query } from '../../effect/index.js';
|
|
14
|
+
import { gql } from '../generated/index.js';
|
|
15
|
+
export const Disconnect = Query.make('Disconnect', gql(`
|
|
16
|
+
mutation Disconnect($sessionId: HexEncoded!) {
|
|
17
|
+
disconnect(sessionId: $sessionId)
|
|
18
|
+
}
|
|
19
|
+
`));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Query } from '../../effect/index.js';
|
|
2
|
+
export declare const FetchTermsAndConditions: Query.Query<import("../generated/graphql.js").FetchTermsAndConditionsQuery, import("../generated/graphql.js").Exact<{
|
|
3
|
+
[key: string]: never;
|
|
4
|
+
}>, Query.Query.QueryFn<import("../generated/graphql.js").FetchTermsAndConditionsQuery, import("../generated/graphql.js").Exact<{
|
|
5
|
+
[key: string]: never;
|
|
6
|
+
}>>>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// This file is part of MIDNIGHT-WALLET-SDK.
|
|
2
|
+
// Copyright (C) Midnight Foundation
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// You may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { Query } from '../../effect/index.js';
|
|
14
|
+
import { gql } from '../generated/index.js';
|
|
15
|
+
export const FetchTermsAndConditions = Query.make('FetchTermsAndConditions', gql(`
|
|
16
|
+
query FetchTermsAndConditions {
|
|
17
|
+
block {
|
|
18
|
+
systemParameters {
|
|
19
|
+
termsAndConditions {
|
|
20
|
+
hash
|
|
21
|
+
url
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
`));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Query } from '../../effect/index.js';
|
|
2
|
+
export declare const TransactionHistoryDetail: Query.Query<import("../generated/graphql.js").TransactionHistoryDetailQuery, import("../generated/graphql.js").Exact<{
|
|
3
|
+
transactionHash: import("../generated/graphql.js").Scalars["HexEncoded"]["input"];
|
|
4
|
+
}>, Query.Query.QueryFn<import("../generated/graphql.js").TransactionHistoryDetailQuery, import("../generated/graphql.js").Exact<{
|
|
5
|
+
transactionHash: import("../generated/graphql.js").Scalars["HexEncoded"]["input"];
|
|
6
|
+
}>>>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// This file is part of MIDNIGHT-WALLET-SDK.
|
|
2
|
+
// Copyright (C) Midnight Foundation
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// You may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { gql } from '../generated/index.js';
|
|
14
|
+
import { Query } from '../../effect/index.js';
|
|
15
|
+
export const TransactionHistoryDetail = Query.make('TransactionHistoryDetail', gql(`
|
|
16
|
+
query TransactionHistoryDetail($transactionHash: HexEncoded!) {
|
|
17
|
+
transactions(offset: {hash: $transactionHash}) {
|
|
18
|
+
__typename
|
|
19
|
+
hash
|
|
20
|
+
block {
|
|
21
|
+
timestamp
|
|
22
|
+
}
|
|
23
|
+
... on RegularTransaction {
|
|
24
|
+
transactionResult {
|
|
25
|
+
status
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
`));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Query } from '../../effect/index.js';
|
|
2
|
+
export declare const TransactionStatus: Query.Query<import("../generated/graphql.js").TransactionStatusQuery, import("../generated/graphql.js").Exact<{
|
|
3
|
+
transactionId: import("../generated/graphql.js").Scalars["HexEncoded"]["input"];
|
|
4
|
+
}>, Query.Query.QueryFn<import("../generated/graphql.js").TransactionStatusQuery, import("../generated/graphql.js").Exact<{
|
|
5
|
+
transactionId: import("../generated/graphql.js").Scalars["HexEncoded"]["input"];
|
|
6
|
+
}>>>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of MIDNIGHT-WALLET-SDK.
|
|
3
|
+
* Copyright (C) Midnight Foundation
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* You may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
import { gql } from '../generated/index.js';
|
|
16
|
+
import { Query } from '../../effect/index.js';
|
|
17
|
+
export const TransactionStatus = Query.make('TransactionStatus', gql(`
|
|
18
|
+
query TransactionStatus($transactionId: HexEncoded!) {
|
|
19
|
+
transactions(offset: {identifier: $transactionId}) {
|
|
20
|
+
__typename
|
|
21
|
+
... on RegularTransaction {
|
|
22
|
+
identifiers
|
|
23
|
+
transactionResult {
|
|
24
|
+
segments {
|
|
25
|
+
id
|
|
26
|
+
success
|
|
27
|
+
}
|
|
28
|
+
status
|
|
29
|
+
__typename
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
`));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// This file is part of MIDNIGHT-WALLET-SDK.
|
|
2
|
+
// Copyright (C) Midnight Foundation
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// You may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
export * from './Connect.js';
|
|
14
|
+
export * from './Disconnect.js';
|
|
15
|
+
export * from './BlockHash.js';
|
|
16
|
+
export * from './FetchTermsAndConditions.js';
|
|
17
|
+
export * from './TransactionStatus.js';
|
|
18
|
+
export * from './TransactionHistoryDetail.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// This file is part of MIDNIGHT-WALLET-SDK.
|
|
2
|
+
// Copyright (C) Midnight Foundation
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// You may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
14
|
+
import { Effect, Option } from 'effect';
|
|
15
|
+
import { randomUUID } from 'node:crypto';
|
|
16
|
+
import { buildTestEnvironmentVariables, getComposeDirectory } from '@midnightntwrk/wallet-sdk-utilities/testing';
|
|
17
|
+
import { DockerComposeEnvironment, Wait } from 'testcontainers';
|
|
18
|
+
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
|
|
19
|
+
import { HttpQueryClient } from '../../../effect/index.js';
|
|
20
|
+
import { BlockHash } from '../BlockHash.js';
|
|
21
|
+
const timeout_minutes = (mins) => 1_000 * 60 * mins;
|
|
22
|
+
const environmentId = randomUUID();
|
|
23
|
+
const environmentVars = buildTestEnvironmentVariables(['APP_INFRA_SECRET'], {
|
|
24
|
+
additionalVars: {
|
|
25
|
+
TESTCONTAINERS_UID: environmentId,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
const environment = new DockerComposeEnvironment(getComposeDirectory(), 'docker-compose.yml')
|
|
29
|
+
// The test below assumes indexer is able to serve blocks, so we wait for it to index at least one block
|
|
30
|
+
// Otherwise the test below would be flakey or not precise enough to be useful
|
|
31
|
+
// Inspecting logs is not the best idea, but here it's the only way
|
|
32
|
+
.withWaitStrategy(`indexer_${environmentId}`, Wait.forLogMessage(/block indexed/))
|
|
33
|
+
.withEnvironment(environmentVars);
|
|
34
|
+
describe('BlockHash query', () => {
|
|
35
|
+
describe('with available Indexer Server', () => {
|
|
36
|
+
let startedEnvironment = undefined;
|
|
37
|
+
const getIndexerPort = () => startedEnvironment?.getContainer(`indexer_${environmentId}`)?.getMappedPort(8088) ?? 8088;
|
|
38
|
+
beforeAll(async () => {
|
|
39
|
+
startedEnvironment = await environment.up();
|
|
40
|
+
}, timeout_minutes(3));
|
|
41
|
+
afterAll(async () => {
|
|
42
|
+
await startedEnvironment?.down();
|
|
43
|
+
}, timeout_minutes(1));
|
|
44
|
+
it('should fail with ClientError for unknown URL', async () => {
|
|
45
|
+
await BlockHash.run({ offset: null }).pipe(Effect.catchSome((err) => (err._tag === 'ClientError' ? Option.some(Effect.succeed(void 0)) : Option.none())), Effect.catchAll((err) => Effect.fail(`Encountered unexpected '${err._tag}' error: ${err.message}`)), Effect.flatMap((data) => (data ? Effect.fail('Unexpectedly received data') : Effect.succeed(void 0))), Effect.provide(HttpQueryClient.layer({ url: `http://127.0.0.1:${getIndexerPort()}/a__p__i/v3/graphql` })), Effect.scoped, Effect.runPromise);
|
|
46
|
+
}, timeout_minutes(1));
|
|
47
|
+
it('should invoke GraphQL query', async () => {
|
|
48
|
+
// Expect a result containing a block with any height and hash value.
|
|
49
|
+
const blockExpectation = expect.objectContaining({
|
|
50
|
+
block: expect.objectContaining({
|
|
51
|
+
height: expect.any(Number),
|
|
52
|
+
hash: expect.any(String),
|
|
53
|
+
}),
|
|
54
|
+
});
|
|
55
|
+
await Effect.gen(function* () {
|
|
56
|
+
const query = yield* BlockHash;
|
|
57
|
+
const result = yield* query({ offset: null });
|
|
58
|
+
expect(result).toEqual(blockExpectation);
|
|
59
|
+
}).pipe(Effect.provide(HttpQueryClient.layer({ url: `http://127.0.0.1:${getIndexerPort()}/api/v4/graphql` })), Effect.scoped, Effect.catchAll((err) => Effect.fail(`Encountered unexpected error: ${err.message}`)), Effect.runPromise);
|
|
60
|
+
}, timeout_minutes(1));
|
|
61
|
+
});
|
|
62
|
+
it('should support query function injection', async () => {
|
|
63
|
+
const block = { block: { height: 1_000, hash: 'SOME_HASH', ledgerParameters: '0x0', timestamp: 1 } };
|
|
64
|
+
const blockExpectation = expect.objectContaining({
|
|
65
|
+
block: expect.objectContaining({
|
|
66
|
+
height: block.block.height,
|
|
67
|
+
hash: block.block.hash,
|
|
68
|
+
ledgerParameters: block.block.ledgerParameters,
|
|
69
|
+
timestamp: block.block.timestamp,
|
|
70
|
+
}),
|
|
71
|
+
});
|
|
72
|
+
const mockedQueryFn = vi.fn();
|
|
73
|
+
mockedQueryFn.mockReturnValue(Effect.succeed(block));
|
|
74
|
+
await Effect.gen(function* () {
|
|
75
|
+
const query = yield* BlockHash;
|
|
76
|
+
const result = yield* query({ offset: null });
|
|
77
|
+
expect(result).toEqual(blockExpectation);
|
|
78
|
+
}).pipe(Effect.provideService(BlockHash.tag, mockedQueryFn), Effect.provide(HttpQueryClient.layer({ url: 'http://127.0.0.1:8088/a__p__i/v3/graphql' })), Effect.scoped, Effect.catchAll((err) => Effect.fail(`Encountered unexpected error: ${err.message}`)), Effect.runPromise);
|
|
79
|
+
await Effect.gen(function* () {
|
|
80
|
+
const result = yield* BlockHash.run({ offset: null });
|
|
81
|
+
expect(result).toEqual(blockExpectation);
|
|
82
|
+
}).pipe(Effect.provideService(BlockHash.tag, mockedQueryFn), Effect.provide(HttpQueryClient.layer({ url: 'http://127.0.0.1:8088/a__p__i/v3/graphql' })), Effect.scoped, Effect.catchAll((err) => Effect.fail(`Encountered unexpected error: ${err.message}`)), Effect.runPromise);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Subscription } from '../../effect/index.js';
|
|
2
|
+
export declare const DustLedgerEvents: Subscription.Subscription<import("../generated/graphql.js").DustLedgerEventsSubscription, import("../generated/graphql.js").Exact<{
|
|
3
|
+
id: import("../generated/graphql.js").InputMaybe<import("../generated/graphql.js").Scalars["Int"]["input"]>;
|
|
4
|
+
}>, Subscription.Subscription.SubscriptionFn<import("../generated/graphql.js").DustLedgerEventsSubscription, import("../generated/graphql.js").Exact<{
|
|
5
|
+
id: import("../generated/graphql.js").InputMaybe<import("../generated/graphql.js").Scalars["Int"]["input"]>;
|
|
6
|
+
}>>>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// This file is part of MIDNIGHT-WALLET-SDK.
|
|
2
|
+
// Copyright (C) Midnight Foundation
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// You may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { Subscription } from '../../effect/index.js';
|
|
14
|
+
import { gql } from '../generated/index.js';
|
|
15
|
+
export const DustLedgerEvents = Subscription.make('DustLedgerEvents', gql(`
|
|
16
|
+
subscription DustLedgerEvents($id: Int) {
|
|
17
|
+
dustLedgerEvents(id: $id) {
|
|
18
|
+
type: __typename
|
|
19
|
+
id
|
|
20
|
+
raw
|
|
21
|
+
maxId
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
`));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Subscription } from '../../effect/index.js';
|
|
2
|
+
export declare const ShieldedTransactions: Subscription.Subscription<import("../generated/graphql.js").ShieldedTransactionsSubscription, import("../generated/graphql.js").Exact<{
|
|
3
|
+
sessionId: import("../generated/graphql.js").Scalars["HexEncoded"]["input"];
|
|
4
|
+
index: import("../generated/graphql.js").InputMaybe<import("../generated/graphql.js").Scalars["Int"]["input"]>;
|
|
5
|
+
}>, Subscription.Subscription.SubscriptionFn<import("../generated/graphql.js").ShieldedTransactionsSubscription, import("../generated/graphql.js").Exact<{
|
|
6
|
+
sessionId: import("../generated/graphql.js").Scalars["HexEncoded"]["input"];
|
|
7
|
+
index: import("../generated/graphql.js").InputMaybe<import("../generated/graphql.js").Scalars["Int"]["input"]>;
|
|
8
|
+
}>>>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// This file is part of MIDNIGHT-WALLET-SDK.
|
|
2
|
+
// Copyright (C) Midnight Foundation
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// You may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { Subscription } from '../../effect/index.js';
|
|
14
|
+
import { gql } from '../generated/index.js';
|
|
15
|
+
export const ShieldedTransactions = Subscription.make('ShieldedTransactions', gql(`
|
|
16
|
+
subscription ShieldedTransactions($sessionId: HexEncoded!, $index: Int) {
|
|
17
|
+
shieldedTransactions(sessionId: $sessionId, index: $index) {
|
|
18
|
+
__typename
|
|
19
|
+
... on ShieldedTransactionsProgress {
|
|
20
|
+
highestEndIndex
|
|
21
|
+
highestCheckedEndIndex
|
|
22
|
+
highestRelevantEndIndex
|
|
23
|
+
}
|
|
24
|
+
... on RelevantTransaction {
|
|
25
|
+
transaction {
|
|
26
|
+
id
|
|
27
|
+
raw
|
|
28
|
+
hash
|
|
29
|
+
protocolVersion
|
|
30
|
+
identifiers
|
|
31
|
+
startIndex
|
|
32
|
+
endIndex
|
|
33
|
+
fees {
|
|
34
|
+
paidFees
|
|
35
|
+
estimatedFees
|
|
36
|
+
}
|
|
37
|
+
transactionResult {
|
|
38
|
+
status
|
|
39
|
+
segments {
|
|
40
|
+
id
|
|
41
|
+
success
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
collapsedMerkleTree {
|
|
46
|
+
startIndex
|
|
47
|
+
endIndex
|
|
48
|
+
update
|
|
49
|
+
protocolVersion
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
`));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Subscription } from '../../effect/index.js';
|
|
2
|
+
export declare const UnshieldedTransactions: Subscription.Subscription<import("../generated/graphql.js").UnshieldedTransactionsSubscription, import("../generated/graphql.js").Exact<{
|
|
3
|
+
address: import("../generated/graphql.js").Scalars["UnshieldedAddress"]["input"];
|
|
4
|
+
transactionId: import("../generated/graphql.js").InputMaybe<import("../generated/graphql.js").Scalars["Int"]["input"]>;
|
|
5
|
+
}>, Subscription.Subscription.SubscriptionFn<import("../generated/graphql.js").UnshieldedTransactionsSubscription, import("../generated/graphql.js").Exact<{
|
|
6
|
+
address: import("../generated/graphql.js").Scalars["UnshieldedAddress"]["input"];
|
|
7
|
+
transactionId: import("../generated/graphql.js").InputMaybe<import("../generated/graphql.js").Scalars["Int"]["input"]>;
|
|
8
|
+
}>>>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// This file is part of MIDNIGHT-WALLET-SDK.
|
|
2
|
+
// Copyright (C) Midnight Foundation
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// You may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { Subscription } from '../../effect/index.js';
|
|
14
|
+
import { gql } from '../generated/index.js';
|
|
15
|
+
export const UnshieldedTransactions = Subscription.make('UnshieldedTransactions', gql(`
|
|
16
|
+
subscription UnshieldedTransactions($address: UnshieldedAddress!, $transactionId: Int) {
|
|
17
|
+
unshieldedTransactions(address: $address, transactionId: $transactionId) {
|
|
18
|
+
... on UnshieldedTransaction {
|
|
19
|
+
type: __typename
|
|
20
|
+
transaction {
|
|
21
|
+
type: __typename
|
|
22
|
+
id
|
|
23
|
+
hash
|
|
24
|
+
protocolVersion
|
|
25
|
+
block {
|
|
26
|
+
timestamp
|
|
27
|
+
}
|
|
28
|
+
... on RegularTransaction {
|
|
29
|
+
identifiers
|
|
30
|
+
fees {
|
|
31
|
+
paidFees
|
|
32
|
+
estimatedFees
|
|
33
|
+
}
|
|
34
|
+
transactionResult {
|
|
35
|
+
status
|
|
36
|
+
segments {
|
|
37
|
+
id
|
|
38
|
+
success
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
createdUtxos {
|
|
44
|
+
owner
|
|
45
|
+
tokenType
|
|
46
|
+
value
|
|
47
|
+
outputIndex
|
|
48
|
+
intentHash
|
|
49
|
+
ctime
|
|
50
|
+
registeredForDustGeneration
|
|
51
|
+
}
|
|
52
|
+
spentUtxos {
|
|
53
|
+
owner
|
|
54
|
+
tokenType
|
|
55
|
+
value
|
|
56
|
+
outputIndex
|
|
57
|
+
intentHash
|
|
58
|
+
ctime
|
|
59
|
+
registeredForDustGeneration
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
... on UnshieldedTransactionsProgress {
|
|
63
|
+
type: __typename
|
|
64
|
+
highestTransactionId
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
`));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Subscription } from '../../effect/index.js';
|
|
2
|
+
export declare const ZswapEvents: Subscription.Subscription<import("../generated/graphql.js").ZswapEventsSubscription, import("../generated/graphql.js").Exact<{
|
|
3
|
+
id: import("../generated/graphql.js").InputMaybe<import("../generated/graphql.js").Scalars["Int"]["input"]>;
|
|
4
|
+
}>, Subscription.Subscription.SubscriptionFn<import("../generated/graphql.js").ZswapEventsSubscription, import("../generated/graphql.js").Exact<{
|
|
5
|
+
id: import("../generated/graphql.js").InputMaybe<import("../generated/graphql.js").Scalars["Int"]["input"]>;
|
|
6
|
+
}>>>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// This file is part of MIDNIGHT-WALLET-SDK.
|
|
2
|
+
// Copyright (C) Midnight Foundation
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// You may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { Subscription } from '../../effect/index.js';
|
|
14
|
+
import { gql } from '../generated/index.js';
|
|
15
|
+
export const ZswapEvents = Subscription.make('ZswapEvents', gql(`
|
|
16
|
+
subscription ZswapEvents($id: Int) {
|
|
17
|
+
zswapLedgerEvents(id: $id) {
|
|
18
|
+
id
|
|
19
|
+
raw
|
|
20
|
+
protocolVersion
|
|
21
|
+
maxId
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
`));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// This file is part of MIDNIGHT-WALLET-SDK.
|
|
2
|
+
// Copyright (C) Midnight Foundation
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// You may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
export * from './DustLedgerEvents.js';
|
|
14
|
+
export * from './ShieldedTransactions.js';
|
|
15
|
+
export * from './UnshieldedTransactions.js';
|
|
16
|
+
export * from './ZswapEvents.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// This file is part of MIDNIGHT-WALLET-SDK.
|
|
2
|
+
// Copyright (C) Midnight Foundation
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// You may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { Effect, Stream } from 'effect';
|
|
14
|
+
import { randomUUID } from 'node:crypto';
|
|
15
|
+
import { buildTestEnvironmentVariables, getComposeDirectory } from '@midnightntwrk/wallet-sdk-utilities/testing';
|
|
16
|
+
import { DockerComposeEnvironment, Wait } from 'testcontainers';
|
|
17
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
18
|
+
import { HttpQueryClient, WsSubscriptionClient } from '../../../effect/index.js';
|
|
19
|
+
import { Connect, Disconnect } from '../../queries/index.js';
|
|
20
|
+
import { ShieldedTransactions } from '../ShieldedTransactions.js';
|
|
21
|
+
const KNOWN_VIEWING_KEY = 'mn_shield-esk_undeployed1d45kgmnfva58gwn9de3hy7tsw35k7m3dwdjkxun9wskkketetdmrzhf6dlyj7u8juj68fd4psnkqhjxh32sec0q480vzswg8kd485e2kljcsmxqc0u';
|
|
22
|
+
const timeout_minutes = (mins) => 1_000 * 60 * mins;
|
|
23
|
+
const environmentId = randomUUID();
|
|
24
|
+
const environmentVars = buildTestEnvironmentVariables(['APP_INFRA_SECRET'], {
|
|
25
|
+
additionalVars: {
|
|
26
|
+
TESTCONTAINERS_UID: environmentId,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
const environment = new DockerComposeEnvironment(getComposeDirectory(), 'docker-compose.yml')
|
|
30
|
+
.withWaitStrategy(`node_${environmentId}`, Wait.forListeningPorts())
|
|
31
|
+
.withWaitStrategy(`indexer_${environmentId}`, Wait.forListeningPorts())
|
|
32
|
+
.withEnvironment(environmentVars);
|
|
33
|
+
describe('Wallet subscription', () => {
|
|
34
|
+
describe('with available Indexer Server', () => {
|
|
35
|
+
let startedEnvironment = undefined;
|
|
36
|
+
const getIndexerPort = () => startedEnvironment?.getContainer(`indexer_${environmentId}`).getMappedPort(8088) ?? 8088;
|
|
37
|
+
beforeAll(async () => {
|
|
38
|
+
startedEnvironment = await environment.up();
|
|
39
|
+
}, timeout_minutes(3));
|
|
40
|
+
afterAll(async () => {
|
|
41
|
+
await startedEnvironment?.down();
|
|
42
|
+
}, timeout_minutes(1));
|
|
43
|
+
it('should stream GraphQL subscription', async () => {
|
|
44
|
+
const makeScopedSession = Effect.acquireRelease(Connect.run({ viewingKey: KNOWN_VIEWING_KEY }), (session) => Disconnect.run({ sessionId: session.connect }).pipe(Effect.catchAll((_) => Effect.void)));
|
|
45
|
+
await Effect.gen(function* () {
|
|
46
|
+
const session = yield* makeScopedSession;
|
|
47
|
+
const events = yield* ShieldedTransactions.run({
|
|
48
|
+
sessionId: session.connect,
|
|
49
|
+
index: null,
|
|
50
|
+
}).pipe(Stream.take(2), Stream.tap((data) => Effect.log(data.shieldedTransactions.__typename)), Stream.runCollect);
|
|
51
|
+
expect(events).toHaveLength(2);
|
|
52
|
+
}).pipe(Effect.provide(HttpQueryClient.layer({ url: `http://127.0.0.1:${getIndexerPort()}/api/v4/graphql` })), Effect.provide(WsSubscriptionClient.layer({ url: `ws://127.0.0.1:${getIndexerPort()}/api/v4/graphql/ws` })), Effect.scoped, Effect.runPromise);
|
|
53
|
+
}, timeout_minutes(1));
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|