-
Notifications
You must be signed in to change notification settings - Fork 0
/
muxed-test-vectors.js
142 lines (135 loc) · 5.44 KB
/
muxed-test-vectors.js
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
131
132
133
134
135
136
137
138
139
140
141
142
const {createSourceAccount} = require('./create-source-account')
const {
Server,
TransactionBuilder,
MuxedAccount,
Operation,
Networks,
Asset,
Account,
Keypair,
Claimant,
BASE_FEE
} = require('stellar-sdk')
async function generateMuxedTestVectors() {
const horizon = new Server('https://horizon-testnet.stellar.org'),
networkPassphrase = Networks.TESTNET
const sourceKeypair1 = await createSourceAccount(),
sourceKeypair2 = await createSourceAccount(),
destKeypair = Keypair.random()
console.log('Creating test transaction with a combination of muxed accounts...')
const sourceAccount1 = await horizon.loadAccount(sourceKeypair1.publicKey()),
sourceAccount2 = await horizon.loadAccount(sourceKeypair2.publicKey()),
destAccount = new Account(destKeypair.publicKey(), '1')
const tx = new TransactionBuilder(new MuxedAccount(sourceAccount1, '18446744073709551615'), {
fee: (3 * BASE_FEE).toString(),
networkPassphrase,
withMuxing: true
})
.enableMuxedAccounts()
.addOperation(Operation.createAccount({
source: new MuxedAccount(sourceAccount1, '0').accountId(),
destination: destKeypair.publicKey(),
startingBalance: '10',
withMuxing: true
}))
.addOperation(Operation.payment({
destination: new MuxedAccount(destAccount, '1').accountId(),
asset: Asset.native(),
amount: '10',
withMuxing: true
}))
.addOperation(Operation.pathPaymentStrictReceive({
source: new MuxedAccount(sourceAccount1, '2').accountId(),
destination: new MuxedAccount(destAccount, '2').accountId(),
sendAsset: Asset.native(),
destAsset: Asset.native(),
destAmount: '10',
sendMax: '10',
withMuxing: true
}))
.addOperation(Operation.changeTrust({
source: new MuxedAccount(sourceAccount1, '6').accountId(),
asset: new Asset('TMP', destKeypair.publicKey()),
withMuxing: true
}))
.addOperation(Operation.manageSellOffer({
source: new MuxedAccount(sourceAccount1, '3').accountId(),
amount: '10',
buying: new Asset('TMP', destKeypair.publicKey()),
selling: Asset.native(),
price: 1,
withMuxing: true
}))
.addOperation(Operation.createPassiveSellOffer({
source: new MuxedAccount(sourceAccount1, '4').accountId(),
amount: '10',
buying: new Asset('TMP', destKeypair.publicKey()),
selling: Asset.native(),
price: 1.1,
withMuxing: true
}))
.addOperation(Operation.setOptions({
source: new MuxedAccount(sourceAccount1, '5').accountId(),
homeDomain: '-',
withMuxing: true
}))
.addOperation(Operation.manageData({
source: new MuxedAccount(sourceAccount1, '10').accountId(),
name: 'tmp',
value: 'tmp',
withMuxing: true
}))
.addOperation(Operation.bumpSequence({
source: new MuxedAccount(sourceAccount1, '11').accountId(),
bumpTo: '8446744073709551615',
withMuxing: true
}))
.addOperation(Operation.manageBuyOffer({
source: new MuxedAccount(sourceAccount1, '12').accountId(),
buyAmount: '10',
buying: new Asset('TMP', destKeypair.publicKey()),
selling: Asset.native(),
price: 1.2,
withMuxing: true
}))
.addOperation(Operation.pathPaymentStrictSend({
destination: new MuxedAccount(destAccount, '13').accountId(),
sendAsset: Asset.native(),
destAsset: Asset.native(),
sendAmount: '10',
destMin: '10',
withMuxing: true
}))
.addOperation(Operation.createClaimableBalance({
source: new MuxedAccount(sourceAccount1, '14').accountId(),
amount: '10',
asset: Asset.native(),
claimants: [new Claimant(sourceKeypair1.publicKey(), Claimant.predicateUnconditional())],
withMuxing: true
}))
.addOperation(Operation.accountMerge({
source: new MuxedAccount(sourceAccount2, '8').accountId(),
destination: new MuxedAccount(destAccount, '8').accountId(),
withMuxing: true
}))
.setTimeout(180)
.build()
tx.sign(sourceKeypair1)
tx.sign(sourceKeypair2)
const bump = TransactionBuilder.buildFeeBumpTransaction(new MuxedAccount(sourceAccount2, '18446744073709551615').accountId(), (6 * BASE_FEE).toString(), tx, networkPassphrase, true)
bump.sign(sourceKeypair2)
// Sign the transaction to prove you are actually the person sending it.
try {
const res = await horizon.submitTransaction(bump)
console.log(`✓ - Test transaction with muxed accounts submitted. Tx hash: ${res.hash}`)
console.log(`https://stellar.expert/explorer/testnet/tx/${res.hash}`)
} catch (e) {
if (e.response && e.response.status === 400 && e.response.data.extras) {
console.error(`Transaction failed with result code ${JSON.stringify(e.response.data.extras.result_codes, null, ' ')}`)
return
}
console.error('Test transaction failed', e)
}
}
module.exports = {generateMuxedTestVectors}