@@ -95,6 +95,16 @@ describe('Stacks: Contract Builder', function () {
95
95
96
96
it ( 'an unsigned self stacking contract call transaction' , async ( ) => {
97
97
const builder = initTxBuilder ( ) ;
98
+ /* Contract call in clarity POX-4
99
+ (define-public (stack-stx (amount-ustx uint)
100
+ (pox-addr (tuple (version (buff 1)) (hashbytes (buff 32))))
101
+ (start-burn-ht uint)
102
+ (lock-period uint)
103
+ (signer-sig (optional (buff 65)))
104
+ (signer-key (buff 33))
105
+ (max-amount uint)
106
+ (auth-id uint))
107
+ */
98
108
builder . functionArgs ( [
99
109
{ type : 'uint128' , val : '400000000' } ,
100
110
{
@@ -106,6 +116,12 @@ describe('Stacks: Contract Builder', function () {
106
116
} ,
107
117
{ type : 'uint128' , val : '52800' } ,
108
118
{ type : 'uint128' , val : '2' } ,
119
+ // Nakamoto upgrade new 4 parameters
120
+ // https://docs.stacks.co/nakamoto-upgrade/signing-and-stacking/stacking-flow#solo-stacker-flow
121
+ { type : 'optional' , val : { type : 'buffer' , val : Buffer . from ( 'some-hash' ) } } ,
122
+ { type : 'buffer' , val : Buffer . from ( 'some-hash' ) } ,
123
+ { type : 'uint128' , val : '340282366920938463463374607431768211455' } ,
124
+ { type : 'uint128' , val : '123456' } ,
109
125
] ) ;
110
126
builder . fromPubKey ( testData . TX_SENDER . pub ) ;
111
127
builder . numberSignatures ( 1 ) ;
@@ -167,6 +183,16 @@ describe('Stacks: Contract Builder', function () {
167
183
168
184
it ( 'a signed self stacking contract call' , async ( ) => {
169
185
const builder = initTxBuilder ( ) ;
186
+ /* Contract call in clarity POX-4
187
+ (define-public (stack-stx (amount-ustx uint)
188
+ (pox-addr (tuple (version (buff 1)) (hashbytes (buff 32))))
189
+ (start-burn-ht uint)
190
+ (lock-period uint)
191
+ (signer-sig (optional (buff 65)))
192
+ (signer-key (buff 33))
193
+ (max-amount uint)
194
+ (auth-id uint))
195
+ */
170
196
builder . functionArgs ( [
171
197
{ type : 'uint128' , val : '400000000' } ,
172
198
{
@@ -178,6 +204,12 @@ describe('Stacks: Contract Builder', function () {
178
204
} ,
179
205
{ type : 'uint128' , val : '52800' } ,
180
206
{ type : 'uint128' , val : '2' } ,
207
+ // Nakamoto upgrade new 4 parameters
208
+ // https://docs.stacks.co/nakamoto-upgrade/signing-and-stacking/stacking-flow#solo-stacker-flow
209
+ { type : 'optional' , val : { type : 'buffer' , val : Buffer . from ( 'some-hash' ) } } ,
210
+ { type : 'buffer' , val : Buffer . from ( 'some-hash' ) } ,
211
+ { type : 'uint128' , val : '340282366920938463463374607431768211455' } ,
212
+ { type : 'uint128' , val : '123456' } ,
181
213
] ) ;
182
214
builder . sign ( { key : testData . TX_SENDER . prv } ) ;
183
215
const tx = await builder . build ( ) ;
@@ -199,6 +231,42 @@ describe('Stacks: Contract Builder', function () {
199
231
tx . inputs [ 0 ] . value . should . equal ( '0' ) ;
200
232
} ) ;
201
233
234
+ // TODO: remove support to this contract version after STX fork
235
+ // https://bitgoinc.atlassian.net/browse/EA-3482
236
+ it ( 'a signed pox-3 backward support pre-fork self stacking contract call' , async ( ) => {
237
+ const builder = initTxBuilder ( ) ;
238
+ builder . functionArgs ( [
239
+ { type : 'uint128' , val : '400000000' } ,
240
+ {
241
+ type : 'tuple' ,
242
+ val : [
243
+ { key : 'hashbytes' , type : 'buffer' , val : Buffer . from ( 'some-hash' ) } ,
244
+ { key : 'version' , type : 'buffer' , val : new BigNum ( 1 ) . toBuffer ( ) } ,
245
+ ] ,
246
+ } ,
247
+ { type : 'uint128' , val : '52800' } ,
248
+ { type : 'uint128' , val : '2' } ,
249
+ ] ) ;
250
+ builder . sign ( { key : testData . TX_SENDER . prv } ) ;
251
+ const tx = await builder . build ( ) ;
252
+
253
+ const txJson = tx . toJson ( ) ;
254
+ should . deepEqual ( txJson . payload . contractAddress , testData . CONTRACT_ADDRESS ) ;
255
+ should . deepEqual ( txJson . payload . contractName , testData . CONTRACT_NAME ) ;
256
+ should . deepEqual ( txJson . payload . functionName , testData . CONTRACT_FUNCTION_NAME ) ;
257
+ should . deepEqual ( txJson . nonce , 0 ) ;
258
+ should . deepEqual ( txJson . fee . toString ( ) , '180' ) ;
259
+ should . deepEqual ( tx . toBroadcastFormat ( ) , testData . POX_3_SIGNED_SELF_STACK_CONTRACT_CALL ) ;
260
+
261
+ tx . type . should . equal ( TransactionType . ContractCall ) ;
262
+ tx . outputs . length . should . equal ( 1 ) ;
263
+ tx . outputs [ 0 ] . address . should . equal ( testData . CONTRACT_ADDRESS ) ;
264
+ tx . outputs [ 0 ] . value . should . equal ( '0' ) ;
265
+ tx . inputs . length . should . equal ( 1 ) ;
266
+ tx . inputs [ 0 ] . address . should . equal ( testData . TX_SENDER . address ) ;
267
+ tx . inputs [ 0 ] . value . should . equal ( '0' ) ;
268
+ } ) ;
269
+
202
270
it ( 'a signed contract call transaction' , async ( ) => {
203
271
const amount = 123 ;
204
272
const builder = initTxBuilder ( ) ;
@@ -246,7 +314,9 @@ describe('Stacks: Contract Builder', function () {
246
314
should . deepEqual ( txJson . payload . functionName , testData . CONTRACT_FUNCTION_NAME ) ;
247
315
should . deepEqual ( txJson . nonce , 0 ) ;
248
316
should . deepEqual ( txJson . fee . toString ( ) , '180' ) ;
249
- should . deepEqual ( txJson . payload . functionArgs . length , 4 ) ;
317
+ // Now stacks-stx self-stacking supports 8 parameters
318
+ // https://docs.stacks.co/nakamoto-upgrade/signing-and-stacking/stacking-flow#solo-stacker-flow
319
+ should . deepEqual ( txJson . payload . functionArgs . length , 8 ) ;
250
320
should . deepEqual ( tx . toBroadcastFormat ( ) , testData . SIGNED_SELF_STACK_CONTRACT_CALL ) ;
251
321
tx . type . should . equal ( TransactionType . ContractCall ) ;
252
322
tx . outputs . length . should . equal ( 1 ) ;
@@ -257,6 +327,29 @@ describe('Stacks: Contract Builder', function () {
257
327
tx . inputs [ 0 ] . value . should . equal ( '0' ) ;
258
328
} ) ;
259
329
330
+ // TODO: remove support to this contract version after STX fork
331
+ // https://bitgoinc.atlassian.net/browse/EA-3482
332
+ it ( 'a signed serialized pox-3 backward support pre-fork self stacking contract call transaction' , async ( ) => {
333
+ const builder = factory . from ( testData . POX_3_SIGNED_SELF_STACK_CONTRACT_CALL ) ;
334
+ const tx = await builder . build ( ) ;
335
+ const txJson = tx . toJson ( ) ;
336
+ should . deepEqual ( txJson . payload . contractAddress , testData . CONTRACT_ADDRESS ) ;
337
+ should . deepEqual ( txJson . payload . contractName , testData . CONTRACT_NAME ) ;
338
+ should . deepEqual ( txJson . payload . functionName , testData . CONTRACT_FUNCTION_NAME ) ;
339
+ should . deepEqual ( txJson . nonce , 0 ) ;
340
+ should . deepEqual ( txJson . fee . toString ( ) , '180' ) ;
341
+ // POX-3 stacks-stx self-stacking supports 4 parameters
342
+ should . deepEqual ( txJson . payload . functionArgs . length , 4 ) ;
343
+ should . deepEqual ( tx . toBroadcastFormat ( ) , testData . POX_3_SIGNED_SELF_STACK_CONTRACT_CALL ) ;
344
+ tx . type . should . equal ( TransactionType . ContractCall ) ;
345
+ tx . outputs . length . should . equal ( 1 ) ;
346
+ tx . outputs [ 0 ] . address . should . equal ( testData . CONTRACT_ADDRESS ) ;
347
+ tx . outputs [ 0 ] . value . should . equal ( '0' ) ;
348
+ tx . inputs . length . should . equal ( 1 ) ;
349
+ tx . inputs [ 0 ] . address . should . equal ( testData . TX_SENDER . address ) ;
350
+ tx . inputs [ 0 ] . value . should . equal ( '0' ) ;
351
+ } ) ;
352
+
260
353
it ( 'a multisig transfer transaction' , async ( ) => {
261
354
const builder = initTxBuilder ( ) ;
262
355
builder . functionArgs ( [ { type : 'optional' , val : { type : 'int128' , val : '123' } } ] ) ;
@@ -374,7 +467,10 @@ describe('Stacks: Contract Builder', function () {
374
467
} ) ;
375
468
it ( 'a contract call with an invalid contract name' , ( ) => {
376
469
const builder = initTxBuilder ( ) ;
377
- assert . throws ( ( ) => builder . contractName ( 'pox-2' ) , / O n l y p o x - 3 a n d s e n d - m a n y - m e m o c o n t r a c t s s u p p o r t e d / ) ;
470
+ assert . throws (
471
+ ( ) => builder . contractName ( 'pox-2' ) ,
472
+ / O n l y p o x - 3 , p o x - 4 a n d s e n d - m a n y - m e m o c o n t r a c t s s u p p o r t e d /
473
+ ) ;
378
474
} ) ;
379
475
it ( 'a contract call with an invalid contract function name' , ( ) => {
380
476
const builder = initTxBuilder ( ) ;
0 commit comments