@xyo-network/xl1-rpc 1.7.16 → 1.7.17

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.
@@ -1,7 +1,12 @@
1
- import { Account } from '@xyo-network/account'
2
1
  import type { AccountInstance } from '@xyo-network/account-model'
2
+ import { PayloadBuilder } from '@xyo-network/payload-builder'
3
+ import type { Payload } from '@xyo-network/payload-model'
4
+ import { HDWallet } from '@xyo-network/wallet'
5
+ import type { AllowedBlockPayload, HashPayload } from '@xyo-network/xl1-protocol'
6
+ import { HashSchema } from '@xyo-network/xl1-protocol'
7
+ import { ADDRESS_INDEX, generateXyoBaseWalletFromPhrase } from '@xyo-network/xl1-protocol-sdk'
3
8
  import {
4
- beforeEach, describe, expect, it,
9
+ beforeAll, beforeEach, describe, expect, it,
5
10
  } from 'vitest'
6
11
 
7
12
  import { MemoryPermissionsStore, MemoryXyoGateway } from '../../host/index.ts'
@@ -10,6 +15,11 @@ import { MemoryXyoSigner } from '../../signer/index.ts'
10
15
  import { MemoryXyoClient } from '../MemoryXyoClient.ts'
11
16
  import type { XyoClient } from '../XyoClient.ts'
12
17
 
18
+ type TestPayload = Payload<{
19
+ id: string
20
+ schema: 'network.xyo.test'
21
+ }>
22
+
13
23
  describe('Client', () => {
14
24
  const endpoint = 'http://localhost:8080/rpc'
15
25
  const dataLakeEndpoint = 'http://localhost:8080/chain/archivist'
@@ -17,28 +27,42 @@ describe('Client', () => {
17
27
  let signer: MemoryXyoSigner
18
28
  let store: MemoryPermissionsStore
19
29
  let gateway: MemoryXyoGateway
20
- let sut: XyoClient
30
+ let client: XyoClient
21
31
 
22
32
  beforeEach(async () => {
23
- account = await Account.random()
33
+ const mnemonic = process.env.XL1_PRODUCER__MNEMONIC ?? HDWallet.generateMnemonic()
34
+ const wallet = await generateXyoBaseWalletFromPhrase(mnemonic)
35
+ account = await wallet.derivePath(ADDRESS_INDEX.XYO)
24
36
  signer = new MemoryXyoSigner(account)
25
-
26
37
  store = new MemoryPermissionsStore()
27
38
  gateway = new MemoryXyoGateway(signer, store)
28
- await gateway.addConnection('localhost', new RpcXyoConnection({ endpoint }))
29
- sut = new MemoryXyoClient(store, { localhost: gateway })
39
+ await gateway.addConnection('localhost', new RpcXyoConnection({ endpoint, account }))
40
+ client = new MemoryXyoClient(store, { localhost: gateway })
30
41
  })
31
42
 
32
43
  describe('gateways', () => {
33
44
  describe('activeConnection', () => {
45
+ let onChainPayloads: AllowedBlockPayload[]
46
+ let offChainPayloads: Payload[]
47
+ beforeAll(async () => {
48
+ const id = new PayloadBuilder<TestPayload>({ schema: 'network.xyo.test' }).fields({ id: Date.now().toString() }).build()
49
+ const hash = await PayloadBuilder.hash(id)
50
+ const hashPayload: HashPayload = new PayloadBuilder<HashPayload>({ schema: HashSchema }).fields({ hash }).build()
51
+ onChainPayloads = [hashPayload]
52
+ offChainPayloads = [id]
53
+ })
34
54
  it('should be defined', () => {
35
- const gateway = sut.gateways.localhost.activeConnection()
55
+ const gateway = client.gateways.localhost.activeConnection()
36
56
  expect(gateway).toBeDefined()
37
57
  })
38
58
  it('should allow retrieving the chain ID', async () => {
39
- const chainId = await sut.gateways.localhost?.activeConnection()?.viewer?.chainId()
59
+ const chainId = await client.gateways.localhost?.activeConnection()?.viewer?.chainId()
40
60
  expect(chainId).toBeDefined()
41
61
  })
62
+ it.only('should allow for submitting transactions', async () => {
63
+ const transaction = await client.gateways.localhost?.activeConnection()?.submitTransaction?.(onChainPayloads, offChainPayloads)
64
+ expect(transaction).toBeDefined()
65
+ })
42
66
  })
43
67
  })
44
68
  })
@@ -1,2 +1,3 @@
1
+ export * from './confirmTransaction.ts'
1
2
  export * from './RpcXyoConnection.ts'
2
3
  export * from './XyoConnection.ts'