Resolve "Blockchain Adapter: Add Chaingraph Adapter"
This commit is contained in:
@@ -0,0 +1,184 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { GraphQLClient } from '../../src/utils/index.js';
|
||||
import {
|
||||
monitorSyncTipsSubscriptionQuery,
|
||||
monitorSyncTipsQuery,
|
||||
monitorSyncTipsSchema,
|
||||
} from '../../src/blockchain/blockchain-chaingraph-helpers.js';
|
||||
|
||||
const chaingraphServer = 'https://demo.chaingraph.cash/v1/graphql';
|
||||
|
||||
describe('GraphQLClient', () => {
|
||||
const graphQLClient = new GraphQLClient(chaingraphServer);
|
||||
|
||||
it("should succesfully subscribe to 'MonitorSyncTips' messages and receive a valid response from server", async () => {
|
||||
/**
|
||||
* Query in SDL:
|
||||
*
|
||||
`subscription MonitorSyncTips ($nameFilter: String = "bchn-mainnet") {
|
||||
node (where: { name: { _like: $nameFilter } }) {
|
||||
name
|
||||
user_agent
|
||||
latest_tip: accepted_blocks(
|
||||
limit: 1,
|
||||
order_by: { block_internal_id: desc }
|
||||
) {
|
||||
accepted_at
|
||||
block {
|
||||
hash
|
||||
height
|
||||
}
|
||||
}
|
||||
}
|
||||
}`
|
||||
*/
|
||||
const response = await graphQLClient.subscribe(
|
||||
'MonitorSyncTipsSubscriptionTest',
|
||||
monitorSyncTipsSubscriptionQuery,
|
||||
true, // wait For response on subscribe
|
||||
{
|
||||
chainFilter: 'bchn-chipnet',
|
||||
},
|
||||
);
|
||||
|
||||
expect(response).toBeTypeOf('object');
|
||||
expect(response).not.toBeInstanceOf(Error);
|
||||
expect(response).not.toBeNull();
|
||||
|
||||
await graphQLClient.unsubscribe(['MonitorSyncTipsSubscriptionTest']);
|
||||
});
|
||||
|
||||
it("should succesfully query latest 'MonitorSyncTips'", async () => {
|
||||
/**
|
||||
* Query in SDL:
|
||||
*
|
||||
`query MonitorSyncTips ( $chainFilter: String = "bchn-mainnet" ) {
|
||||
node ( where: { name: { _like: $chainFilter } } ) {
|
||||
name
|
||||
user_agent
|
||||
latest_tip: accepted_blocks(
|
||||
limit: 1,
|
||||
order_by: { block_internal_id: desc }
|
||||
) {
|
||||
accepted_at
|
||||
block {
|
||||
hash
|
||||
height
|
||||
}
|
||||
}
|
||||
}
|
||||
}`
|
||||
*/
|
||||
const response = await graphQLClient.request(
|
||||
'monitorSyncTipsQuery',
|
||||
monitorSyncTipsQuery,
|
||||
{ chainFilter: 'bchn-mainnet' },
|
||||
);
|
||||
|
||||
// Validate the response notification payload.
|
||||
monitorSyncTipsSchema.parse(response);
|
||||
|
||||
expect(response).toBeTypeOf('object');
|
||||
expect(response).not.toBeInstanceOf(Error);
|
||||
expect(response).not.toBeNull();
|
||||
});
|
||||
|
||||
it("should succesfully request 'GetJonathan100CashAccount' and receive a valid response from server", async () => {
|
||||
/**
|
||||
* Query in SDL:
|
||||
*
|
||||
`query GetJonathan100CashAccount {
|
||||
search_output_prefix(
|
||||
args: { locking_bytecode_prefix_hex: "6a0401010101084a6f6e617468616e" },
|
||||
where: {
|
||||
transaction: { block_inclusions: { block: { height: { _eq: 563720 } } } }
|
||||
}
|
||||
) {
|
||||
transaction {
|
||||
hash
|
||||
data_carrier_outputs {
|
||||
locking_bytecode
|
||||
output_index
|
||||
}
|
||||
block_inclusions {
|
||||
block {
|
||||
hash
|
||||
height
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`
|
||||
*/
|
||||
const getJonathan100CashAccount = {
|
||||
query: {
|
||||
__name: 'GetJonathan100CashAccount',
|
||||
search_output_prefix: {
|
||||
__args: {
|
||||
args: {
|
||||
locking_bytecode_prefix_hex: '6a0401010101084a6f6e617468616e',
|
||||
},
|
||||
where: {
|
||||
transaction: {
|
||||
block_inclusions: {
|
||||
block: {
|
||||
height: {
|
||||
_eq: 563720,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
transaction: {
|
||||
hash: true,
|
||||
data_carrier_outputs: {
|
||||
locking_bytecode: true,
|
||||
output_index: true,
|
||||
},
|
||||
block_inclusions: {
|
||||
block: {
|
||||
hash: true,
|
||||
height: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const expectedResponse = {
|
||||
data: {
|
||||
search_output_prefix: [
|
||||
{
|
||||
transaction: {
|
||||
hash: '\\x590d1fdf7e04af0ee08f9194bb9e8d1971bdcbf55d29303d5bf32d4eae5e7136',
|
||||
data_carrier_outputs: [
|
||||
{
|
||||
locking_bytecode:
|
||||
'\\x6a0401010101084a6f6e617468616e1501ebdeb6430f3d16a9c6758d6c0d7a400c8e6bbee4',
|
||||
output_index: '0',
|
||||
},
|
||||
],
|
||||
block_inclusions: [
|
||||
{
|
||||
block: {
|
||||
hash: '\\x000000000000000002abbeff5f6fb22a0b3b5c2685c6ef4ed2d2257ed54e9dcb',
|
||||
height: '563720',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const response = await graphQLClient.request(
|
||||
'GetJonathan100CashAccount',
|
||||
getJonathan100CashAccount,
|
||||
);
|
||||
|
||||
expect(response).toEqual(expectedResponse);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user