|
1 | 1 | import { DeFiDRpcError, MasterNodeRegTestContainer } from '@defichain/testcontainers'
|
2 | 2 | import { getProviders, MockProviders } from '../provider.mock'
|
3 |
| -import { P2WPKHTransactionBuilder } from '../../src' |
| 3 | +import { P2WPKHTransactionBuilder, Prevout } from '../../src' |
4 | 4 | import { fundEllipticPair, sendTransaction } from '../test.utils'
|
5 | 5 | import BigNumber from 'bignumber.js'
|
6 | 6 | import { Interface, ethers } from 'ethers'
|
@@ -166,7 +166,17 @@ describe('transferDomain', () => {
|
166 | 166 | }]
|
167 | 167 | }
|
168 | 168 |
|
169 |
| - const txn = await builder.account.transferDomain(transferDomain, dvmScript, { maximumAmount: 50 }) |
| 169 | + const utxos: any[] = await container.call('listunspent', [ |
| 170 | + 1, 9999999, [dvmAddr], true |
| 171 | + ]) |
| 172 | + const utxo: Prevout = { |
| 173 | + txid: utxos[0].txid, |
| 174 | + vout: utxos[0].vout, |
| 175 | + value: new BigNumber(utxos[0].amount), |
| 176 | + script: dvmScript, |
| 177 | + tokenId: utxos[0].tokenId |
| 178 | + } |
| 179 | + const txn = await builder.account.transferDomain(transferDomain, dvmScript, [utxo]) |
170 | 180 | const promise = sendTransaction(testing.container, txn)
|
171 | 181 |
|
172 | 182 | await expect(promise).rejects.toThrow(DeFiDRpcError)
|
@@ -223,7 +233,17 @@ describe('transferDomain', () => {
|
223 | 233 | }]
|
224 | 234 | }
|
225 | 235 |
|
226 |
| - const txn = await builder.account.transferDomain(transferDomain, dvmScript, { maximumAmount: 50 }) |
| 236 | + const utxos: any[] = await container.call('listunspent', [ |
| 237 | + 1, 9999999, [dvmAddr], true |
| 238 | + ]) |
| 239 | + const utxo: Prevout = { |
| 240 | + txid: utxos[0].txid, |
| 241 | + vout: utxos[0].vout, |
| 242 | + value: new BigNumber(utxos[0].amount), |
| 243 | + script: dvmScript, |
| 244 | + tokenId: utxos[0].tokenId |
| 245 | + } |
| 246 | + const txn = await builder.account.transferDomain(transferDomain, dvmScript, [utxo]) |
227 | 247 | const promise = sendTransaction(testing.container, txn)
|
228 | 248 |
|
229 | 249 | await expect(promise).rejects.toThrow(DeFiDRpcError)
|
@@ -280,7 +300,17 @@ describe('transferDomain', () => {
|
280 | 300 | }]
|
281 | 301 | }
|
282 | 302 |
|
283 |
| - const txn = await builder.account.transferDomain(transferDomain, dvmScript, { maximumAmount: 50 }) |
| 303 | + const utxos: any[] = await container.call('listunspent', [ |
| 304 | + 1, 9999999, [dvmAddr], true |
| 305 | + ]) |
| 306 | + const utxo: Prevout = { |
| 307 | + txid: utxos[0].txid, |
| 308 | + vout: utxos[0].vout, |
| 309 | + value: new BigNumber(utxos[0].amount), |
| 310 | + script: dvmScript, |
| 311 | + tokenId: utxos[0].tokenId |
| 312 | + } |
| 313 | + const txn = await builder.account.transferDomain(transferDomain, dvmScript, [utxo]) |
284 | 314 | const promise = sendTransaction(testing.container, txn)
|
285 | 315 |
|
286 | 316 | await expect(promise).rejects.toThrow(DeFiDRpcError)
|
@@ -337,7 +367,17 @@ describe('transferDomain', () => {
|
337 | 367 | }]
|
338 | 368 | }
|
339 | 369 |
|
340 |
| - const txn = await builder.account.transferDomain(transferDomain, dvmScript, { maximumAmount: 50 }) |
| 370 | + const utxos: any[] = await container.call('listunspent', [ |
| 371 | + 1, 9999999, [dvmAddr], true |
| 372 | + ]) |
| 373 | + const utxo: Prevout = { |
| 374 | + txid: utxos[0].txid, |
| 375 | + vout: utxos[0].vout, |
| 376 | + value: new BigNumber(utxos[0].amount), |
| 377 | + script: dvmScript, |
| 378 | + tokenId: utxos[0].tokenId |
| 379 | + } |
| 380 | + const txn = await builder.account.transferDomain(transferDomain, dvmScript, [utxo]) |
341 | 381 | const promise = sendTransaction(testing.container, txn)
|
342 | 382 |
|
343 | 383 | await expect(promise).rejects.toThrow(DeFiDRpcError)
|
@@ -394,7 +434,17 @@ describe('transferDomain', () => {
|
394 | 434 | }]
|
395 | 435 | }
|
396 | 436 |
|
397 |
| - const txn = await builder.account.transferDomain(transferDomain, dvmScript, { maximumAmount: 50 }) |
| 437 | + const utxos: any[] = await container.call('listunspent', [ |
| 438 | + 1, 9999999, [dvmAddr], true |
| 439 | + ]) |
| 440 | + const utxo: Prevout = { |
| 441 | + txid: utxos[0].txid, |
| 442 | + vout: utxos[0].vout, |
| 443 | + value: new BigNumber(utxos[0].amount), |
| 444 | + script: dvmScript, |
| 445 | + tokenId: utxos[0].tokenId |
| 446 | + } |
| 447 | + const txn = await builder.account.transferDomain(transferDomain, dvmScript, [utxo]) |
398 | 448 | const promise = sendTransaction(testing.container, txn)
|
399 | 449 |
|
400 | 450 | await expect(promise).rejects.toThrow(DeFiDRpcError)
|
@@ -451,7 +501,17 @@ describe('transferDomain', () => {
|
451 | 501 | }]
|
452 | 502 | }
|
453 | 503 |
|
454 |
| - const txn = await builder.account.transferDomain(transferDomain, dvmScript, { maximumAmount: 50 }) |
| 504 | + const utxos: any[] = await container.call('listunspent', [ |
| 505 | + 1, 9999999, [dvmAddr], true |
| 506 | + ]) |
| 507 | + const utxo: Prevout = { |
| 508 | + txid: utxos[0].txid, |
| 509 | + vout: utxos[0].vout, |
| 510 | + value: new BigNumber(utxos[0].amount), |
| 511 | + script: dvmScript, |
| 512 | + tokenId: utxos[0].tokenId |
| 513 | + } |
| 514 | + const txn = await builder.account.transferDomain(transferDomain, dvmScript, [utxo]) |
455 | 515 | const promise = sendTransaction(testing.container, txn)
|
456 | 516 |
|
457 | 517 | await expect(promise).rejects.toThrow(DeFiDRpcError)
|
@@ -510,7 +570,17 @@ describe('transferDomain', () => {
|
510 | 570 | }]
|
511 | 571 | }
|
512 | 572 |
|
513 |
| - const txn = await builder.account.transferDomain(transferDomain, invalidDvmScript, { maximumAmount: 50 }) |
| 573 | + const utxos: any[] = await container.call('listunspent', [ |
| 574 | + 1, 9999999, [dvmAddr], true |
| 575 | + ]) |
| 576 | + const utxo: Prevout = { |
| 577 | + txid: utxos[0].txid, |
| 578 | + vout: utxos[0].vout, |
| 579 | + value: new BigNumber(utxos[0].amount), |
| 580 | + script: dvmScript, |
| 581 | + tokenId: utxos[0].tokenId |
| 582 | + } |
| 583 | + const txn = await builder.account.transferDomain(transferDomain, invalidDvmScript, [utxo]) |
514 | 584 | const promise = sendTransaction(testing.container, txn)
|
515 | 585 |
|
516 | 586 | await expect(promise).rejects.toThrow(DeFiDRpcError)
|
@@ -568,7 +638,17 @@ describe('transferDomain', () => {
|
568 | 638 | }]
|
569 | 639 | }
|
570 | 640 |
|
571 |
| - const txn = await builder.account.transferDomain(transferDomain, invalidDvmScript, { maximumAmount: 50 }) |
| 641 | + const utxos: any[] = await container.call('listunspent', [ |
| 642 | + 1, 9999999, [dvmAddr], true |
| 643 | + ]) |
| 644 | + const utxo: Prevout = { |
| 645 | + txid: utxos[0].txid, |
| 646 | + vout: utxos[0].vout, |
| 647 | + value: new BigNumber(utxos[0].amount), |
| 648 | + script: dvmScript, |
| 649 | + tokenId: utxos[0].tokenId |
| 650 | + } |
| 651 | + const txn = await builder.account.transferDomain(transferDomain, invalidDvmScript, [utxo]) |
572 | 652 | const promise = sendTransaction(testing.container, txn)
|
573 | 653 |
|
574 | 654 | await expect(promise).rejects.toThrow(DeFiDRpcError)
|
@@ -669,7 +749,17 @@ describe('transferDomain', () => {
|
669 | 749 | }]
|
670 | 750 | }
|
671 | 751 |
|
672 |
| - const txn = await builder.account.transferDomain(transferDomain, dvmScript, { maximumAmount: 50 }) |
| 752 | + const utxos: any[] = await container.call('listunspent', [ |
| 753 | + 1, 9999999, [dvmAddr], true |
| 754 | + ]) |
| 755 | + const utxo: Prevout = { |
| 756 | + txid: utxos[0].txid, |
| 757 | + vout: utxos[0].vout, |
| 758 | + value: new BigNumber(utxos[0].amount), |
| 759 | + script: dvmScript, |
| 760 | + tokenId: utxos[0].tokenId |
| 761 | + } |
| 762 | + const txn = await builder.account.transferDomain(transferDomain, dvmScript, [utxo]) |
673 | 763 | const promise = sendTransaction(testing.container, txn)
|
674 | 764 |
|
675 | 765 | await expect(promise).rejects.toThrow(DeFiDRpcError)
|
@@ -875,7 +965,17 @@ describe('transferDomain', () => {
|
875 | 965 | ]
|
876 | 966 | }
|
877 | 967 |
|
878 |
| - const txn = await builder.account.transferDomain(transferDomain, dvmScript, { maximumAmount: 50 }) |
| 968 | + const utxos: any[] = await container.call('listunspent', [ |
| 969 | + 1, 9999999, [dvmAddr], true |
| 970 | + ]) |
| 971 | + const utxo: Prevout = { |
| 972 | + txid: utxos[0].txid, |
| 973 | + vout: utxos[0].vout, |
| 974 | + value: new BigNumber(utxos[0].amount), |
| 975 | + script: dvmScript, |
| 976 | + tokenId: utxos[0].tokenId |
| 977 | + } |
| 978 | + const txn = await builder.account.transferDomain(transferDomain, dvmScript, [utxo]) |
879 | 979 | const promise = sendTransaction(testing.container, txn)
|
880 | 980 | await expect(promise).rejects.toThrow(DeFiDRpcError)
|
881 | 981 | await expect(promise).rejects.toThrow('TransferDomain currently only supports a single transfer per transaction')
|
@@ -935,10 +1035,18 @@ describe('transferDomain', () => {
|
935 | 1035 | }
|
936 | 1036 | }]
|
937 | 1037 | }
|
938 |
| - // NOTE(canonbrother): `maximumAmount` is a workaround to grab only single vin |
939 |
| - // since maximumCount behaviour does not return by provided value |
940 |
| - // but catch up total utxos of the tokenId |
941 |
| - const txn = await builder.account.transferDomain(transferDomain, dvmScript, { maximumAmount: 50 }) |
| 1038 | + |
| 1039 | + const utxos: any[] = await container.call('listunspent', [ |
| 1040 | + 1, 9999999, [dvmAddr], true |
| 1041 | + ]) |
| 1042 | + const utxo: Prevout = { |
| 1043 | + txid: utxos[0].txid, |
| 1044 | + vout: utxos[0].vout, |
| 1045 | + value: new BigNumber(utxos[0].amount), |
| 1046 | + script: dvmScript, |
| 1047 | + tokenId: utxos[0].tokenId |
| 1048 | + } |
| 1049 | + const txn = await builder.account.transferDomain(transferDomain, dvmScript, [utxo]) |
942 | 1050 | const outs = await sendTransaction(container, txn)
|
943 | 1051 | const encoded: string = OP_CODES.OP_DEFI_TX_TRANSFER_DOMAIN(transferDomain).asBuffer().toString('hex')
|
944 | 1052 | const expectedTransferDomainScript = `6a${encoded}`
|
@@ -1026,7 +1134,17 @@ describe('transferDomain', () => {
|
1026 | 1134 | }]
|
1027 | 1135 | }
|
1028 | 1136 |
|
1029 |
| - const txn = await builder.account.transferDomain(transferDomain, dvmScript, { maximumAmount: 50 }) |
| 1137 | + const utxos: any[] = await container.call('listunspent', [ |
| 1138 | + 1, 9999999, [dvmAddr], true |
| 1139 | + ]) |
| 1140 | + const utxo: Prevout = { |
| 1141 | + txid: utxos[0].txid, |
| 1142 | + vout: utxos[0].vout, |
| 1143 | + value: new BigNumber(utxos[0].amount), |
| 1144 | + script: dvmScript, |
| 1145 | + tokenId: utxos[0].tokenId |
| 1146 | + } |
| 1147 | + const txn = await builder.account.transferDomain(transferDomain, dvmScript, [utxo]) |
1030 | 1148 | const outs = await sendTransaction(container, txn)
|
1031 | 1149 | const encoded: string = OP_CODES.OP_DEFI_TX_TRANSFER_DOMAIN(transferDomain).asBuffer().toString('hex')
|
1032 | 1150 | const expectedTransferDomainScript = `6a${encoded}`
|
@@ -1118,7 +1236,17 @@ describe('transferDomain', () => {
|
1118 | 1236 | }]
|
1119 | 1237 | }
|
1120 | 1238 |
|
1121 |
| - const txn = await builder.account.transferDomain(transferDomain, dvmScript, { maximumAmount: 50 }) |
| 1239 | + const utxos: any[] = await container.call('listunspent', [ |
| 1240 | + 1, 9999999, [dvmAddr], true |
| 1241 | + ]) |
| 1242 | + const utxo: Prevout = { |
| 1243 | + txid: utxos[0].txid, |
| 1244 | + vout: utxos[0].vout, |
| 1245 | + value: new BigNumber(utxos[0].amount), |
| 1246 | + script: dvmScript, |
| 1247 | + tokenId: utxos[0].tokenId |
| 1248 | + } |
| 1249 | + const txn = await builder.account.transferDomain(transferDomain, dvmScript, [utxo]) |
1122 | 1250 | const outs = await sendTransaction(container, txn)
|
1123 | 1251 | const encoded: string = OP_CODES.OP_DEFI_TX_TRANSFER_DOMAIN(transferDomain).asBuffer().toString('hex')
|
1124 | 1252 | const expectedTransferDomainScript = `6a${encoded}`
|
@@ -1205,7 +1333,17 @@ describe('transferDomain', () => {
|
1205 | 1333 | }]
|
1206 | 1334 | }
|
1207 | 1335 |
|
1208 |
| - const txn = await builder.account.transferDomain(transferDomain, dvmScript, { maximumAmount: 50 }) |
| 1336 | + const utxos: any[] = await container.call('listunspent', [ |
| 1337 | + 1, 9999999, [dvmAddr], true |
| 1338 | + ]) |
| 1339 | + const utxo: Prevout = { |
| 1340 | + txid: utxos[0].txid, |
| 1341 | + vout: utxos[0].vout, |
| 1342 | + value: new BigNumber(utxos[0].amount), |
| 1343 | + script: dvmScript, |
| 1344 | + tokenId: utxos[0].tokenId |
| 1345 | + } |
| 1346 | + const txn = await builder.account.transferDomain(transferDomain, dvmScript, [utxo]) |
1209 | 1347 | const outs = await sendTransaction(container, txn)
|
1210 | 1348 | const encoded: string = OP_CODES.OP_DEFI_TX_TRANSFER_DOMAIN(transferDomain).asBuffer().toString('hex')
|
1211 | 1349 | const expectedTransferDomainScript = `6a${encoded}`
|
|
0 commit comments