openchain-nodejs-ts-yxl 1.0.1

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.
Files changed (76) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +66 -0
  3. package/_config.yml +1 -0
  4. package/doc/SDK_CN.md +2003 -0
  5. package/example/atp10TokenDemo.js +319 -0
  6. package/example/exchange.js +184 -0
  7. package/example/offlineSignatureDemo.js +83 -0
  8. package/example/submitTransactionDemo.js +92 -0
  9. package/index.d.ts +186 -0
  10. package/index.js +9 -0
  11. package/lib/account/index.js +234 -0
  12. package/lib/blockchain/block.js +380 -0
  13. package/lib/blockchain/transaction.js +264 -0
  14. package/lib/common/ctp.js +5 -0
  15. package/lib/common/operation/accountSetMetadata.js +55 -0
  16. package/lib/common/operation/accountSetPrivilege.js +90 -0
  17. package/lib/common/operation/activateAccount.js +58 -0
  18. package/lib/common/operation/contractCreate.js +72 -0
  19. package/lib/common/operation/contractInvokeByAsset.js +75 -0
  20. package/lib/common/operation/contractInvokeByBU.js +53 -0
  21. package/lib/common/operation/createLog.js +44 -0
  22. package/lib/common/operation/ctp10TokenApprove.js +59 -0
  23. package/lib/common/operation/ctp10TokenAssign.js +59 -0
  24. package/lib/common/operation/ctp10TokenChangeOwner.js +58 -0
  25. package/lib/common/operation/ctp10TokenIssue.js +78 -0
  26. package/lib/common/operation/ctp10TokenTransfer.js +59 -0
  27. package/lib/common/operation/ctp10TokenTransferFrom.js +60 -0
  28. package/lib/common/operation/issueAsset.js +35 -0
  29. package/lib/common/operation/payAsset.js +62 -0
  30. package/lib/common/operation/payCoin.js +44 -0
  31. package/lib/common/util.js +880 -0
  32. package/lib/contract/index.js +212 -0
  33. package/lib/crypto/protobuf/bundle.json +1643 -0
  34. package/lib/exception/customErrors.js +56 -0
  35. package/lib/exception/errors.js +240 -0
  36. package/lib/exception/index.js +8 -0
  37. package/lib/operation/account.js +193 -0
  38. package/lib/operation/asset.js +106 -0
  39. package/lib/operation/bu.js +52 -0
  40. package/lib/operation/contract.js +184 -0
  41. package/lib/operation/ctp10Token.js +394 -0
  42. package/lib/operation/index.js +30 -0
  43. package/lib/operation/log.js +47 -0
  44. package/lib/sdk.js +70 -0
  45. package/lib/token/asset.js +79 -0
  46. package/lib/token/ctp10Token.js +301 -0
  47. package/lib/token/index.js +17 -0
  48. package/lib/util/index.js +86 -0
  49. package/openchain-sdk-nodejs.iml +9 -0
  50. package/package.json +39 -0
  51. package/test/Ctp10Token.test.js +96 -0
  52. package/test/account.test.js +132 -0
  53. package/test/accountActivateOperation.test.js +99 -0
  54. package/test/accountSetMetadata.test.js +102 -0
  55. package/test/accountSetPrivilege.test.js +66 -0
  56. package/test/asset.test.js +63 -0
  57. package/test/assetIssueOperation.test.js +77 -0
  58. package/test/assetSendOperation.test.js +103 -0
  59. package/test/blob.test.js +128 -0
  60. package/test/block.test.js +165 -0
  61. package/test/buSendOperation.test.js +64 -0
  62. package/test/contract.test.js +64 -0
  63. package/test/contractCreateOperation.test.js +41 -0
  64. package/test/contractCreateTransaction.test.js +116 -0
  65. package/test/contractInvokeByAssetOperation.test.js +109 -0
  66. package/test/contractInvokeByBUOperation.test.js +107 -0
  67. package/test/ctp10TokenApproveOperation.test.js +98 -0
  68. package/test/ctp10TokenAssignOperation.test.js +99 -0
  69. package/test/ctp10TokenChangeOwnerOperation.test.js +98 -0
  70. package/test/ctp10TokenIssueOperation.test.js +40 -0
  71. package/test/ctp10TokenIssueOperationTransaction.test.js +106 -0
  72. package/test/ctp10TokenTransferFromOperation.test.js +101 -0
  73. package/test/ctp10TokenTransferOperation.test.js +98 -0
  74. package/test/log.transaction.test.js +103 -0
  75. package/test/transaction.test.js +166 -0
  76. package/test/util.test.js +93 -0
@@ -0,0 +1,132 @@
1
+ 'use strict';
2
+
3
+ require('chai').should();
4
+ const OpenChainSDK = require('../index');
5
+
6
+ const sdk = new OpenChainSDK({
7
+ host: 'http://localhost/node/api',
8
+ });
9
+
10
+ describe('Test openchain-sdk account service', function() {
11
+
12
+ it('test account.create()', async() => {
13
+ const keypair = await sdk.account.create();
14
+ console.log('keypair',keypair);
15
+ keypair.errorCode.should.equal(0);
16
+ keypair.result.should.be.a('object');
17
+ keypair.result.should.have.property('privateKey').with.lengthOf(56);
18
+ keypair.result.should.have.property('publicKey').with.lengthOf(76);
19
+ keypair.result.should.have.property('address').with.lengthOf(36);
20
+ });
21
+
22
+
23
+ it('test account.getInfo(address)', async() => {
24
+ let address = 'YxLEhaVxxbXABBuj4trYir51UH9SwfyiS6CF';
25
+ let data = await sdk.account.getInfo(address);
26
+ data.should.be.a('object');
27
+ data.errorCode.should.equal(0);
28
+
29
+ address = '';
30
+ data = await sdk.account.getInfo(address);
31
+ data.should.be.a('object');
32
+ data.errorCode.should.equal(11006);
33
+
34
+ address = 'YxLA2RjoKvdx2FcKD63zXi2UQnUsmDVoDvFj';
35
+ // YxLA2RjoKvdx2FcKD63zXi2UQnUsmDVoDvFj
36
+ // aco2EeSCcBjqnjffFP59nxTvrX1iWvs3KANF9
37
+ data = await sdk.account.getInfo(address);
38
+ data.should.be.a('object');
39
+ data.errorCode.should.equal(11006);
40
+
41
+ address = 100;
42
+ data = await sdk.account.getInfo(address);
43
+ data.should.be.a('object');
44
+ data.errorCode.should.equal(11006);
45
+ });
46
+
47
+ it('test account.checkValid(address)', async() => {
48
+ let data = await sdk.account.checkValid('YxLA2RjoKvdx2FcKD63zXi2UQnUsmDVoDvFj');
49
+ data.should.be.a('object');
50
+ data.result.should.be.a('object');
51
+ data.result.should.have.property('isValid').equal(true);
52
+
53
+ data = await sdk.account.checkValid('YxLA2RjoKvdx2FcKD63zXi2UQnUsmDVoDvFj');
54
+ data.should.be.a('object');
55
+ data.result.should.be.a('object');
56
+ data.result.should.have.property('isValid').equal(false);
57
+
58
+ data = await sdk.account.checkValid('');
59
+ data.should.be.a('object');
60
+ data.result.should.be.a('object');
61
+ data.result.should.have.property('isValid').equal(false);
62
+
63
+
64
+ data = await sdk.account.checkValid(123);
65
+ data.should.be.a('object');
66
+ data.result.should.be.a('object');
67
+ data.result.should.have.property('isValid').equal(false);
68
+ });
69
+
70
+ it('test account.getBalance(address)', async() => {
71
+ let address = 'YxLA2RjoKvdx2FcKD63zXi2UQnUsmDVoDvFj';
72
+ let data = await sdk.account.getBalance(address);
73
+ data.should.be.a('object');
74
+ data.errorCode.should.equal(0);
75
+ data.result.should.have.property('balance');
76
+
77
+ address = '';
78
+ data = await sdk.account.getBalance(address);
79
+ data.should.be.a('object');
80
+ data.errorCode.should.equal(11006);
81
+
82
+ address = '123';
83
+ data = await sdk.account.getBalance(address);
84
+ data.should.be.a('object');
85
+ data.errorCode.should.equal(11006);
86
+
87
+ address = 123;
88
+ data = await sdk.account.getBalance(address);
89
+ data.should.be.a('object');
90
+ data.errorCode.should.equal(11006);
91
+ });
92
+
93
+ it('test account.getNonce(address)', async() => {
94
+ let address = 'YxLA2RjoKvdx2FcKD63zXi2UQnUsmDVoDvFj';
95
+ let data = await sdk.account.getNonce(address);
96
+ data.should.be.a('object');
97
+ data.errorCode.should.equal(0);
98
+ data.result.should.have.property('nonce');
99
+
100
+ address = '';
101
+ data = await sdk.account.getNonce(address);
102
+ data.should.be.a('object');
103
+ data.errorCode.should.equal(11006);
104
+ });
105
+
106
+ it('test account.getMetadata()', async() => {
107
+ let data = await sdk.account.getMetadata({
108
+ address: 'adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r',
109
+ key: 'mykey1'
110
+ });
111
+ console.log(data);
112
+ console.log(JSON.stringify(data));
113
+ });
114
+
115
+ it('test account.isActivated()', async() => {
116
+ let data = await sdk.account.isActivated('adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r');
117
+ data.errorCode.should.equal(0);
118
+ data.result.isActivated.should.equal(true);
119
+
120
+ data = await sdk.account.isActivated('YxLA2RjoKvdx2FcKD63zXi2UQnUsmDVoDvFj');
121
+ data.errorCode.should.equal(0);
122
+ data.result.isActivated.should.equal(false);
123
+
124
+ data = await sdk.account.isActivated();
125
+ data.errorCode.should.equal(15016);
126
+
127
+ data = await sdk.account.isActivated('');
128
+ data.errorCode.should.equal(11006);
129
+
130
+ });
131
+
132
+ });
@@ -0,0 +1,99 @@
1
+ 'use strict';
2
+
3
+ require('chai').should();
4
+ const OpenChainSDK = require('../index');
5
+
6
+ const sdk = new OpenChainSDK({
7
+ host: 'localhost/node/api',
8
+ });
9
+
10
+ describe('Test account activate operation', function() {
11
+
12
+ it('test operation.accountActivateOperation()', function() {
13
+
14
+ let data = sdk.operation.accountActivateOperation({
15
+ sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
16
+ destAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
17
+ initBalance: '1000',
18
+ metadata: 'Test Account Activate',
19
+ });
20
+
21
+ data.should.be.a('object');
22
+ data.errorCode.should.equal(0);
23
+ data.result.should.have.property('operation').be.a('object');
24
+ data.result.operation.should.have.property('type');
25
+ data.result.operation.should.have.property('data');
26
+ data.result.operation.type.should.equal('activateAccount');
27
+
28
+ // Invalid sourceAddress
29
+ data = sdk.operation.accountActivateOperation({
30
+ sourceAddress: '',
31
+ destAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
32
+ initBalance: '1000',
33
+ });
34
+ data.errorCode.should.equal(11002);
35
+
36
+ data = sdk.operation.accountActivateOperation({
37
+ sourceAddress: null,
38
+ destAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
39
+ initBalance: '1000',
40
+ });
41
+ data.errorCode.should.equal(11002);
42
+
43
+ // Invalid destAddress
44
+ data = sdk.operation.accountActivateOperation({
45
+ sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
46
+ destAddress: '',
47
+ initBalance: '1000',
48
+ });
49
+ data.errorCode.should.equal(11003);
50
+
51
+ // sourceAddress === destAddress
52
+ data = sdk.operation.accountActivateOperation({
53
+ sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
54
+ destAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
55
+ initBalance: '1000',
56
+ });
57
+ data.errorCode.should.equal(11005);
58
+
59
+ // Invalid initBalance
60
+ data = sdk.operation.accountActivateOperation({
61
+ sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
62
+ destAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
63
+ initBalance: 1000,
64
+ });
65
+ data.errorCode.should.equal(11004);
66
+
67
+ data = sdk.operation.accountActivateOperation({
68
+ sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
69
+ destAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
70
+ initBalance: '',
71
+ });
72
+ data.errorCode.should.equal(11004);
73
+
74
+ data = sdk.operation.accountActivateOperation({
75
+ sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
76
+ destAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
77
+ });
78
+ data.errorCode.should.equal(11004);
79
+
80
+ // Invalid metadata
81
+ data = sdk.operation.accountActivateOperation({
82
+ sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
83
+ destAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
84
+ initBalance: '1000',
85
+ metadata: '',
86
+ });
87
+ data.errorCode.should.equal(15028);
88
+
89
+ data = sdk.operation.accountActivateOperation({
90
+ sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
91
+ destAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
92
+ initBalance: '1000',
93
+ metadata: 123,
94
+ });
95
+ data.errorCode.should.equal(15028);
96
+
97
+ });
98
+
99
+ });
@@ -0,0 +1,102 @@
1
+ 'use strict';
2
+
3
+ require('chai').should();
4
+ const OpenChainSDK = require('../index');
5
+ const BigNumber = require('bignumber.js');
6
+
7
+ const sdk = new OpenChainSDK({
8
+ host: 'localhost/node/api',
9
+ });
10
+
11
+ describe('Test account Set Metadata Operation', function() {
12
+
13
+ it('test operation.accountSetMetadataOperation()', async() => {
14
+
15
+ const privateKey = 'private key';
16
+ const sourceAddress = 'adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r';
17
+
18
+ // Get nonce
19
+ const result = await sdk.account.getNonce(sourceAddress);
20
+ if (result.errorCode !== 0) {
21
+ console.log(result);
22
+ return;
23
+ }
24
+ let nonce = result.result.nonce;
25
+ nonce = new BigNumber(nonce).plus(1).toString(10);
26
+
27
+ // build operation
28
+ let accountSetMetadataOperation = sdk.operation.accountSetMetadataOperation({
29
+ key: 'mykey1',
30
+ value: 'myvalue1',
31
+ // deleteFlag: 1,
32
+ version: '0'
33
+ });
34
+
35
+ if (accountSetMetadataOperation.errorCode !== 0) {
36
+ console.log(accountSetMetadataOperation);
37
+ return;
38
+ }
39
+
40
+ const operationItem = accountSetMetadataOperation.result.operation;
41
+
42
+ console.log(operationItem);
43
+ // return;
44
+ const args = {
45
+ sourceAddress,
46
+ nonce,
47
+ operations: [operationItem],
48
+ signtureNumber: '100',
49
+ };
50
+
51
+ let feeData = await sdk.transaction.evaluateFee(args);
52
+ if (feeData.errorCode !== 0) {
53
+ console.log(feeData);
54
+ return;
55
+ }
56
+
57
+ let feeLimit = feeData.result.feeLimit;
58
+ let gasPrice = feeData.result.gasPrice;
59
+
60
+ // console.log(feeData);
61
+
62
+ // =============================
63
+ // build blob
64
+ // =============================
65
+ let blobInfo = sdk.transaction.buildBlob({
66
+ sourceAddress,
67
+ gasPrice,
68
+ feeLimit,
69
+ nonce,
70
+ operations: [ operationItem ],
71
+ });
72
+
73
+ if (blobInfo.errorCode !== 0) {
74
+ console.log(blobInfo);
75
+ return;
76
+ }
77
+
78
+ let blob = blobInfo.result.transactionBlob;
79
+
80
+ // 3. sign blob
81
+ let signatureInfo = sdk.transaction.sign({
82
+ privateKeys: [ privateKey ],
83
+ blob,
84
+ });
85
+
86
+ if (signatureInfo.errorCode !== 0) {
87
+ console.log(signatureInfo);
88
+ return;
89
+ }
90
+
91
+ let signature = signatureInfo.result.signatures;
92
+ // 4. submit transaction
93
+ let transactionInfo = await sdk.transaction.submit({
94
+ blob,
95
+ signature: signature,
96
+ });
97
+
98
+ console.log(transactionInfo);
99
+ });
100
+
101
+
102
+ });
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+
3
+ require('chai').should();
4
+ const OpenChainSDK = require('../index');
5
+ const BigNumber = require('bignumber.js');
6
+
7
+ const sdk = new OpenChainSDK({
8
+ host: 'localhost/node/api',
9
+ });
10
+
11
+ describe('Test account Set Privilege Operation', function() {
12
+
13
+ it('test operation.accountSetPrivilegeOperation()', async() => {
14
+
15
+ const privateKey = 'private key';
16
+ const sourceAddress = 'adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r';
17
+
18
+ // Get nonce
19
+ const result = await sdk.account.getNonce(sourceAddress);
20
+ if (result.errorCode !== 0) {
21
+ console.log(result);
22
+ return;
23
+ }
24
+ let nonce = result.result.nonce;
25
+ nonce = new BigNumber(nonce).plus(1).toString(10);
26
+
27
+ // build operation
28
+ let accountSetPrivilegeOperation = sdk.operation.accountSetPrivilegeOperation({
29
+ // signers: [{
30
+ // address: 'adxScpCtbeLP2KGRaCkbtrmz8iB5mu6DQcW3r',
31
+ // weight: '0'
32
+ // }],
33
+ typeThresholds: [{
34
+ type: '3',
35
+ threshold: '100',
36
+ }],
37
+ });
38
+
39
+ if (accountSetPrivilegeOperation.errorCode !== 0) {
40
+ console.log(accountSetPrivilegeOperation);
41
+ return;
42
+ }
43
+
44
+ const operationItem = accountSetPrivilegeOperation.result.operation;
45
+
46
+ const args = {
47
+ sourceAddress,
48
+ nonce,
49
+ operations: [operationItem],
50
+ signtureNumber: '100',
51
+ };
52
+
53
+ let feeData = await sdk.transaction.evaluateFee(args);
54
+ if (feeData.errorCode !== 0) {
55
+ console.log(feeData);
56
+ return;
57
+ }
58
+
59
+ let feeLimit = feeData.result.feeLimit;
60
+ let gasPrice = feeData.result.gasPrice;
61
+
62
+ console.log(feeData);
63
+ });
64
+
65
+
66
+ });
@@ -0,0 +1,63 @@
1
+ 'use strict';
2
+
3
+ require('chai').should();
4
+ const OpenChainSDK = require('../index');
5
+
6
+ const sdk = new OpenChainSDK({
7
+ host: 'localhost/node/api',
8
+ });
9
+
10
+ describe('Test asset service', function() {
11
+
12
+ it('test asset.getInfo()', async() => {
13
+ let data = await sdk.token.asset.getInfo({
14
+ address: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
15
+ code: 'BTC',
16
+ issuer: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
17
+ });
18
+ data.errorCode.should.equal(0);
19
+ data.result.should.be.a('object');
20
+ data.result.should.have.property('assets');
21
+ data.result.assets.should.be.a('array');
22
+
23
+ // empty argument
24
+ data = await sdk.token.asset.getInfo();
25
+ data.errorCode.should.equal(15016);
26
+
27
+ // invalid address
28
+ data = await sdk.token.asset.getInfo({
29
+ address: '',
30
+ code: 'BTC',
31
+ issuer: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
32
+ });
33
+ data.errorCode.should.equal(11006);
34
+
35
+ // invalid code
36
+ data = await sdk.token.asset.getInfo({
37
+ address: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
38
+ code: '',
39
+ issuer: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
40
+ });
41
+ data.errorCode.should.equal(11023);
42
+
43
+ // invalid issuer address
44
+ data = await sdk.token.asset.getInfo({
45
+ address: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
46
+ code: 'BTC',
47
+ issuer: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2tA',
48
+ });
49
+ data.errorCode.should.equal(11027);
50
+
51
+ // BTCDEMO asset does not exist
52
+ data = await sdk.token.asset.getInfo({
53
+ address: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
54
+ code: 'BTCDEMO',
55
+ issuer: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
56
+ });
57
+ data.errorCode.should.equal(0);
58
+ data.result.should.be.a('object');
59
+ data.result.should.have.property('assets');
60
+ data.result.assets.should.have.lengthOf(0);
61
+ });
62
+
63
+ });
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ require('chai').should();
4
+ const OpenChainSDK = require('../index');
5
+
6
+ const sdk = new OpenChainSDK({
7
+ host: 'localhost/node/api',
8
+ });
9
+
10
+ describe('Test asset issue operation', function() {
11
+ it('test operation.assetIssueOperation(args)', function() {
12
+ let data = sdk.operation.assetIssueOperation({
13
+ sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
14
+ code: 'leo',
15
+ assetAmount: '20000',
16
+ metadata: 'oh my issue asset',
17
+ });
18
+ data.errorCode.should.equal(0);
19
+ data.result.should.be.a('object');
20
+ data.result.should.have.property('operation');
21
+ data.result.operation.should.be.a('object');
22
+ data.result.operation.should.have.property('type').equal('issueAsset');
23
+ data.result.operation.should.have.property('data');
24
+
25
+ // Invalid sourceAddress
26
+ data = sdk.operation.assetIssueOperation({
27
+ sourceAddress: '',
28
+ code: 'leo',
29
+ assetAmount: '20000',
30
+ metadata: 'oh my issue asset',
31
+ });
32
+ data.errorCode.should.equal(11002);
33
+
34
+ // sourceAddress is undefined
35
+ data = sdk.operation.assetIssueOperation({
36
+ code: 'leo',
37
+ assetAmount: '20000',
38
+ metadata: 'oh my issue asset',
39
+ });
40
+ data.errorCode.should.equal(0);
41
+
42
+ // Invalid code
43
+ data = sdk.operation.assetIssueOperation({
44
+ sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
45
+ code: '',
46
+ assetAmount: '20000',
47
+ metadata: 'oh my issue asset',
48
+ });
49
+ data.errorCode.should.equal(11023);
50
+
51
+ // Invalid assetAmount
52
+ data = sdk.operation.assetIssueOperation({
53
+ sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
54
+ code: 'leo',
55
+ assetAmount: '',
56
+ metadata: 'oh my issue asset',
57
+ });
58
+ data.errorCode.should.equal(11024);
59
+
60
+ // Invalid metadata
61
+ data = sdk.operation.assetIssueOperation({
62
+ sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
63
+ code: 'leo',
64
+ assetAmount: '20000',
65
+ metadata: '',
66
+ });
67
+ data.errorCode.should.equal(15028);
68
+
69
+ // metadata is undefined
70
+ data = sdk.operation.assetIssueOperation({
71
+ sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
72
+ code: 'leo',
73
+ assetAmount: '20000',
74
+ });
75
+ data.errorCode.should.equal(0);
76
+ });
77
+ });
@@ -0,0 +1,103 @@
1
+ 'use strict';
2
+
3
+ require('chai').should();
4
+ const OpenChainSDK = require('../index');
5
+
6
+ const sdk = new OpenChainSDK({
7
+ host: 'localhost/node/api',
8
+ });
9
+
10
+ describe('Test asset send operation', function() {
11
+
12
+ it('test operation.assetSendOperation(args)', function() {
13
+ let data = sdk.operation.assetSendOperation({
14
+ sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
15
+ destAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
16
+ code: 'leo',
17
+ issuer: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
18
+ assetAmount: '100',
19
+ metadata: 'oh my test send asset',
20
+ });
21
+ data.errorCode.should.equal(0);
22
+ data.result.should.be.a('object');
23
+ data.result.should.have.property('operation');
24
+ data.result.operation.should.be.a('object');
25
+ data.result.operation.should.have.property('type').equal('payAsset');
26
+ data.result.operation.should.have.property('data');
27
+
28
+ // sourceAddress === destAddress
29
+ data = sdk.operation.assetSendOperation({
30
+ sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
31
+ destAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
32
+ code: 'leo',
33
+ issuer: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
34
+ assetAmount: '100',
35
+ metadata: 'oh my test send asset',
36
+ });
37
+ data.errorCode.should.equal(11005);
38
+
39
+ // Invalid sourceAddress
40
+ data = sdk.operation.assetSendOperation({
41
+ sourceAddress: '',
42
+ destAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
43
+ code: 'leo',
44
+ issuer: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
45
+ assetAmount: '100',
46
+ metadata: 'oh my test send asset',
47
+ });
48
+ data.errorCode.should.equal(11002);
49
+
50
+ // sourceAddress is undefined
51
+ data = sdk.operation.assetSendOperation({
52
+ destAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
53
+ code: 'leo',
54
+ issuer: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
55
+ assetAmount: '100',
56
+ metadata: 'oh my test send asset',
57
+ });
58
+ data.errorCode.should.equal(0);
59
+
60
+ // Invalid code
61
+ data = sdk.operation.assetSendOperation({
62
+ sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
63
+ destAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
64
+ code: '',
65
+ issuer: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
66
+ assetAmount: '100',
67
+ metadata: 'oh my test send asset',
68
+ });
69
+ data.errorCode.should.equal(11023);
70
+
71
+ // Invalid assetAmount
72
+ data = sdk.operation.assetSendOperation({
73
+ sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
74
+ destAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
75
+ code: 'leo',
76
+ issuer: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
77
+ assetAmount: '',
78
+ metadata: 'oh my test send asset',
79
+ });
80
+ data.errorCode.should.equal(11024);
81
+
82
+ // Invalid metadata
83
+ data = sdk.operation.assetSendOperation({
84
+ sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
85
+ destAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
86
+ code: 'leo',
87
+ issuer: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
88
+ assetAmount: '100',
89
+ metadata: '',
90
+ });
91
+ data.errorCode.should.equal(15028);
92
+
93
+ // metadata is undefined
94
+ data = sdk.operation.assetSendOperation({
95
+ sourceAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
96
+ destAddress: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
97
+ code: 'leo',
98
+ issuer: 'adxSk4rkz84a4fh5xYxfSqmAsnhcWZzrTfG2t',
99
+ assetAmount: '100',
100
+ });
101
+ data.errorCode.should.equal(0);
102
+ });
103
+ });