-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.js
More file actions
130 lines (119 loc) · 3.68 KB
/
Copy pathtest.js
File metadata and controls
130 lines (119 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
'use strict'
const fs = require('fs')
const os = require('os')
const path = require('path')
const { NativeExternalSigner, SdkNode } = require('./index')
const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'rln-node-canary-'))
const signerDataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'rln-node-vls-canary-'))
const signer = NativeExternalSigner.createWithStorage(
'01'.repeat(32),
'regtest',
signerDataDir,
true
)
const node = SdkNode.create({
storage_dir_path: dataDir,
daemon_listening_port: 0,
ldk_peer_listening_port: 0,
network: 'regtest',
max_media_upload_size_mb: 5,
enable_virtual_channels_v0: false,
reuse_addresses: true
})
try {
for (const method of [
'rotateAddress',
'assetLinkCreate',
'listTransactions',
'listTransfers',
'syncWallet',
'walletSnapshot',
'prepareBtcSend',
'commitPreparedBtcSend',
'cancelBtcSendPlan',
'prepareCreateUtxos',
'commitPreparedCreateUtxos',
'cancelCreateUtxosPlan',
'listPendingVanillaTransactions',
'listAddressReceipts',
'prepareRgbSend',
'commitPreparedRgbSend',
'cancelRgbSendPlan',
'listPendingRgbSendPlans',
'listTransactionsByTxid',
'listTransfersByTxid',
'importRgbTransferConsignment',
'importRgbContract',
'apayNew',
'apayNewWithAddress',
'verifyMessage'
]) {
if (typeof node[method] !== 'function') throw new Error(`SdkNode.${method} is missing`)
}
let lockedApayError
try {
node.apayNewWithAddress('02'.repeat(33), 'canary', 'example.com')
} catch (error) {
lockedApayError = error
}
if (!String(lockedApayError?.message ?? lockedApayError).includes('NotInitialized')) {
throw new Error(
`address-attested APay did not reach the locked native node: ${lockedApayError}`
)
}
let invalidSyncRequest
try {
node.syncWallet({ mode: 'routine', typo: true })
} catch (error) {
invalidSyncRequest = error
}
if (!String(invalidSyncRequest?.message ?? invalidSyncRequest).includes('unknown field')) {
throw new Error(`syncWallet accepted an unknown request field: ${invalidSyncRequest}`)
}
let invalidSnapshotLimit
try {
node.walletSnapshot({ max_assets: 0 })
} catch (error) {
invalidSnapshotLimit = error
}
if (!String(invalidSnapshotLimit?.message ?? invalidSnapshotLimit).includes('max_assets')) {
throw new Error(`walletSnapshot accepted max_assets=0: ${invalidSnapshotLimit}`)
}
node.initWithNativeExternalSigner(signer)
const wrongSigner = NativeExternalSigner.create('02'.repeat(32), 'regtest')
try {
let mismatch
try {
node.unlockWithNativeExternalSigner(wrongSigner, {})
} catch (error) {
mismatch = error
}
if (!String(mismatch?.message ?? mismatch).includes('Rln(ExternalSignerMismatch)')) {
throw new Error(`unexpected signer mismatch error: ${mismatch}`)
}
} finally {
wrongSigner.destroy()
}
const result = node.verifyMessage(
'is this compatible?',
'rbgfioj114mh48d8egqx8o9qxqw4fmhe8jbeeabdioxnjk8z3t1ma1hu1fiswpakgucwwzwo6ofycffbsqusqdimugbh41n1g698hr9t'
)
if (!result || typeof result.valid !== 'boolean') {
throw new Error('verifyMessage did not return { valid: boolean }')
}
const bootstrap = signer.bootstrap()
if (typeof bootstrap.node_id !== 'string') throw new Error('signer bootstrap is missing node_id')
} finally {
node.shutdown()
signer.destroy()
const reopenedSigner = NativeExternalSigner.createWithStorage(
'01'.repeat(32),
'regtest',
signerDataDir,
true
)
reopenedSigner.destroy()
fs.rmSync(dataDir, { recursive: true, force: true })
fs.rmSync(signerDataDir, { recursive: true, force: true })
}
console.log('Node binding canary passed')