Skip to content

Commit d521d7b

Browse files
committed
Node Fabric SDK test cases fix
Signed-off-by: sandeep.nishad1 <[email protected]>
1 parent 140796e commit d521d7b

File tree

1 file changed

+54
-18
lines changed

1 file changed

+54
-18
lines changed

sdks/fabric/interoperation-node-sdk/test/AssetManager.js

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,33 +77,43 @@ describe("AssetManager", () => {
7777
it("asset lock fails with invalid parameters", async () => {
7878
let expiryTimeSecs = Math.floor(Date.now()/1000) + 300; // Convert epoch milliseconds to seconds and add 5 minutes
7979
let assetLockInvocation = await assetManager.createHTLC(null, assetType, assetID, recipientECert, "", "", expiryTimeSecs);
80-
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'result');
80+
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'hash', 'result');
8181
expect(assetLockInvocation.preimage).to.be.a("string");
8282
expect(assetLockInvocation.preimage.length).to.equal(0);
83+
expect(assetLockInvocation.hash).to.be.a("string");
84+
expect(assetLockInvocation.hash.length).to.equal(0);
8385
expect(assetLockInvocation.result).to.be.a('boolean');
8486
expect(assetLockInvocation.result).to.equal(false);
8587
assetLockInvocation = await assetManager.createHTLC(amc, "", assetID, recipientECert, "", "", expiryTimeSecs);
86-
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'result');
88+
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'hash', 'result');
8789
expect(assetLockInvocation.preimage).to.be.a("string");
8890
expect(assetLockInvocation.preimage.length).to.equal(0);
91+
expect(assetLockInvocation.hash).to.be.a("string");
92+
expect(assetLockInvocation.hash.length).to.equal(0);
8993
expect(assetLockInvocation.result).to.be.a('boolean');
9094
expect(assetLockInvocation.result).to.equal(false);
9195
assetLockInvocation = await assetManager.createHTLC(amc, assetType, "", recipientECert, "", "", expiryTimeSecs);
92-
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'result');
96+
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'hash', 'result');
9397
expect(assetLockInvocation.preimage).to.be.a("string");
9498
expect(assetLockInvocation.preimage.length).to.equal(0);
99+
expect(assetLockInvocation.hash).to.be.a("string");
100+
expect(assetLockInvocation.hash.length).to.equal(0);
95101
expect(assetLockInvocation.result).to.be.a('boolean');
96102
expect(assetLockInvocation.result).to.equal(false);
97103
assetLockInvocation = await assetManager.createHTLC(amc, assetType, assetID, "", "", "", expiryTimeSecs);
98-
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'result');
104+
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'hash', 'result');
99105
expect(assetLockInvocation.preimage).to.be.a("string");
100106
expect(assetLockInvocation.preimage.length).to.equal(0);
107+
expect(assetLockInvocation.hash).to.be.a("string");
108+
expect(assetLockInvocation.hash.length).to.equal(0);
101109
expect(assetLockInvocation.result).to.be.a('boolean');
102110
expect(assetLockInvocation.result).to.equal(false);
103111
assetLockInvocation = await assetManager.createHTLC(amc, assetType, assetID, recipientECert, "", "", expiryTimeSecs - 600); // Expiry time in the past
104-
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'result');
112+
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'hash', 'result');
105113
expect(assetLockInvocation.preimage).to.be.a("string");
106114
expect(assetLockInvocation.preimage.length).to.equal(0);
115+
expect(assetLockInvocation.hash).to.be.a("string");
116+
expect(assetLockInvocation.hash.length).to.equal(0);
107117
expect(assetLockInvocation.result).to.be.a('boolean');
108118
expect(assetLockInvocation.result).to.equal(false);
109119
});
@@ -115,28 +125,36 @@ describe("AssetManager", () => {
115125
let lockInfoStr = assetManager.createAssetLockInfoSerialized(hashValue, expiryTimeSecs);
116126
amcStub.withArgs("LockAsset", assetAgreementStr, lockInfoStr).resolves(true);
117127
let assetLockInvocation = await assetManager.createHTLC(amc, assetType, assetID, recipientECert, "", hashValue, expiryTimeSecs);
118-
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'result');
128+
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'hash', 'result');
119129
expect(assetLockInvocation.preimage).to.be.a("string");
120130
expect(assetLockInvocation.preimage.length).to.equal(0);
131+
expect(assetLockInvocation.hash).to.be.a("string");
132+
expect(assetLockInvocation.hash).to.equal(hashValue);
121133
expect(assetLockInvocation.result).to.be.a('boolean');
122134
expect(assetLockInvocation.result).to.equal(true);
123135
amcStub.withArgs("LockAsset", assetAgreementStr, sinon.match.any).resolves(true);
124136
assetLockInvocation = await assetManager.createHTLC(amc, assetType, assetID, recipientECert, "", hashValue, expiryTimeSecs);
125-
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'result');
137+
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'hash', 'result');
126138
expect(assetLockInvocation.preimage).to.be.a("string");
127139
expect(assetLockInvocation.preimage.length).to.equal(0);
140+
expect(assetLockInvocation.hash).to.be.a("string");
141+
expect(assetLockInvocation.hash).to.equal(hashValue);
128142
expect(assetLockInvocation.result).to.be.a('boolean');
129143
expect(assetLockInvocation.result).to.equal(true);
130144
assetLockInvocation = await assetManager.createHTLC(amc, assetType, assetID, recipientECert, "", "", expiryTimeSecs);
131-
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'result');
145+
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'hash', 'result');
132146
expect(assetLockInvocation.preimage).to.be.a("string");
133147
expect(assetLockInvocation.preimage.length).to.be.above(0);
148+
expect(assetLockInvocation.hash).to.be.a("string");
149+
expect(assetLockInvocation.hash.length).to.be.above(0);
134150
expect(assetLockInvocation.result).to.be.a('boolean');
135151
expect(assetLockInvocation.result).to.equal(true);
136152
const hashPreimage = "some-preimage";
137153
assetLockInvocation = await assetManager.createHTLC(amc, assetType, assetID, recipientECert, hashPreimage, "", expiryTimeSecs);
138-
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'result');
154+
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'hash', 'result');
139155
expect(assetLockInvocation.preimage).to.equal(hashPreimage);
156+
expect(assetLockInvocation.hash).to.be.a("string");
157+
expect(assetLockInvocation.hash.length).to.be.above(0);
140158
expect(assetLockInvocation.result).to.be.a('boolean');
141159
expect(assetLockInvocation.result).to.equal(true);
142160
const testAttr = assetType + ':' + assetID + ':' + recipientECert + ':' + hashPreimage + ':' + hashValue;
@@ -162,33 +180,43 @@ describe("AssetManager", () => {
162180
it("asset lock fails with invalid parameters", async () => {
163181
let expiryTimeSecs = Math.floor(Date.now()/1000) + 300; // Convert epoch milliseconds to seconds and add 5 minutes
164182
let assetLockInvocation = await assetManager.createFungibleHTLC(null, fungibleAssetType, numUnits, recipientECert, "", "", expiryTimeSecs);
165-
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'result');
183+
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'hash', 'result');
166184
expect(assetLockInvocation.preimage).to.be.a("string");
167185
expect(assetLockInvocation.preimage.length).to.equal(0);
186+
expect(assetLockInvocation.hash).to.be.a("string");
187+
expect(assetLockInvocation.hash.length).to.equal(0);
168188
expect(assetLockInvocation.result).to.be.a('string');
169189
expect(assetLockInvocation.result).to.equal('');
170190
assetLockInvocation = await assetManager.createFungibleHTLC(amc, "", numUnits, recipientECert, "", "", expiryTimeSecs);
171-
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'result');
191+
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'hash', 'result');
172192
expect(assetLockInvocation.preimage).to.be.a("string");
173193
expect(assetLockInvocation.preimage.length).to.equal(0);
194+
expect(assetLockInvocation.hash).to.be.a("string");
195+
expect(assetLockInvocation.hash.length).to.equal(0);
174196
expect(assetLockInvocation.result).to.be.a('string');
175197
expect(assetLockInvocation.result).to.equal('');
176198
assetLockInvocation = await assetManager.createFungibleHTLC(amc, fungibleAssetType, -1, recipientECert, "", "", expiryTimeSecs);
177-
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'result');
199+
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'hash', 'result');
178200
expect(assetLockInvocation.preimage).to.be.a("string");
179201
expect(assetLockInvocation.preimage.length).to.equal(0);
202+
expect(assetLockInvocation.hash).to.be.a("string");
203+
expect(assetLockInvocation.hash.length).to.equal(0);
180204
expect(assetLockInvocation.result).to.be.a('string');
181205
expect(assetLockInvocation.result).to.equal('');
182206
assetLockInvocation = await assetManager.createFungibleHTLC(amc, fungibleAssetType, numUnits, "", "", "", expiryTimeSecs);
183-
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'result');
207+
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'hash', 'result');
184208
expect(assetLockInvocation.preimage).to.be.a("string");
185209
expect(assetLockInvocation.preimage.length).to.equal(0);
210+
expect(assetLockInvocation.hash).to.be.a("string");
211+
expect(assetLockInvocation.hash.length).to.equal(0);
186212
expect(assetLockInvocation.result).to.be.a('string');
187213
expect(assetLockInvocation.result).to.equal('');
188214
assetLockInvocation = await assetManager.createFungibleHTLC(amc, fungibleAssetType, numUnits, recipientECert, "", "", expiryTimeSecs - 600); // Expiry time in the past
189-
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'result');
215+
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'hash', 'result');
190216
expect(assetLockInvocation.preimage).to.be.a("string");
191217
expect(assetLockInvocation.preimage.length).to.equal(0);
218+
expect(assetLockInvocation.hash).to.be.a("string");
219+
expect(assetLockInvocation.hash.length).to.equal(0);
192220
expect(assetLockInvocation.result).to.be.a('string');
193221
expect(assetLockInvocation.result).to.equal('');
194222
});
@@ -201,28 +229,36 @@ describe("AssetManager", () => {
201229
const contractId = "CONTRACT-1234";
202230
amcStub.withArgs("LockFungibleAsset", assetAgreementStr, lockInfoStr).resolves(contractId);
203231
let assetLockInvocation = await assetManager.createFungibleHTLC(amc, fungibleAssetType, numUnits, recipientECert, "", hashValue, expiryTimeSecs);
204-
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'result');
232+
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'hash', 'result');
205233
expect(assetLockInvocation.preimage).to.be.a("string");
206234
expect(assetLockInvocation.preimage.length).to.equal(0);
235+
expect(assetLockInvocation.hash).to.be.a("string");
236+
expect(assetLockInvocation.hash).to.equal(hashValue);
207237
expect(assetLockInvocation.result).to.be.a('string');
208238
expect(assetLockInvocation.result).to.equal(contractId);
209239
amcStub.withArgs("LockFungibleAsset", assetAgreementStr, sinon.match.any).resolves(contractId);
210240
assetLockInvocation = await assetManager.createFungibleHTLC(amc, fungibleAssetType, numUnits, recipientECert, "", hashValue, expiryTimeSecs);
211-
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'result');
241+
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'hash', 'result');
212242
expect(assetLockInvocation.preimage).to.be.a("string");
213243
expect(assetLockInvocation.preimage.length).to.equal(0);
244+
expect(assetLockInvocation.hash).to.be.a("string");
245+
expect(assetLockInvocation.hash).to.equal(hashValue);
214246
expect(assetLockInvocation.result).to.be.a('string');
215247
expect(assetLockInvocation.result).to.equal(contractId);
216248
assetLockInvocation = await assetManager.createFungibleHTLC(amc, fungibleAssetType, numUnits, recipientECert, "", "", expiryTimeSecs);
217-
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'result');
249+
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'hash', 'result');
218250
expect(assetLockInvocation.preimage).to.be.a("string");
219251
expect(assetLockInvocation.preimage.length).to.be.above(0);
252+
expect(assetLockInvocation.hash).to.be.a("string");
253+
expect(assetLockInvocation.hash.length).to.be.above(0);
220254
expect(assetLockInvocation.result).to.be.a('string');
221255
expect(assetLockInvocation.result).to.equal(contractId);
222256
const hashPreimage = "some-preimage";
223257
assetLockInvocation = await assetManager.createFungibleHTLC(amc, fungibleAssetType, numUnits, recipientECert, hashPreimage, "", expiryTimeSecs);
224-
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'result');
258+
expect(assetLockInvocation).to.be.an('object').that.has.all.keys('preimage', 'hash', 'result');
225259
expect(assetLockInvocation.preimage).to.equal(hashPreimage);
260+
expect(assetLockInvocation.hash).to.be.a("string");
261+
expect(assetLockInvocation.hash.length).to.be.above(0);
226262
expect(assetLockInvocation.result).to.be.a('string');
227263
expect(assetLockInvocation.result).to.equal(contractId);
228264
const testAttr = contractId + ':' + fungibleAssetType + ':' + numUnits + ':' + recipientECert + ':' + hashPreimage + ':' + hashValue;

0 commit comments

Comments
 (0)