Skip to content

Commit 4217aee

Browse files
committed
[DONE] defer
1 parent a6452ce commit 4217aee

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

cc/golang/contracts.js

+13
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,20 @@ describe('invoke', function () {
7979
it('standard', async () => {
8080
await assert.rejects(contract.evaluateTransaction('standard'));
8181
assert.equal(await contract.evaluateTransaction('standard', 'a'), 'a');
82+
const result = await contract.evaluateTransaction('now');
83+
const chaincodeTime = new Date(result);
84+
assert.ok(chaincodeTime < new Date());
8285

86+
});
87+
it('defer', async () => {
88+
89+
try {
90+
await contract.evaluateTransaction('StupidContract:defer');
91+
} catch (e) {
92+
const {code, details} = e;
93+
assert.equal(code, 2);
94+
assert.equal(details[0].message, 'chaincode response 500, defer');
95+
}
8396

8497
});
8598
it('stress 10', async () => {

cc/golang/ecosystem.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as helper from '../../app/helper.js';
2-
import {installAll} from '../../app/chaincodeOperator.js';
3-
import {installAndApprove, commit} from '../testutil.js';
2+
import {installAndApprove, commit, getContract} from '../testutil.js';
43

54
const chaincodeID = 'ecosystem';
65
const orderers = helper.newOrderers();
@@ -9,10 +8,7 @@ const orderer = orderers[0];
98

109
describe('deploy', function () {
1110
this.timeout(0);
12-
it('install', async () => {
13-
await installAll(chaincodeID);
14-
});
15-
it('query installed & approve', async () => {
11+
it('install & approve', async () => {
1612

1713
const orgs = ['icdd', 'astri.org'];
1814
for (const org of orgs) {
@@ -27,7 +23,14 @@ describe('deploy', function () {
2723
});
2824
describe('invoke', function () {
2925
this.timeout(0);
26+
const contract = getContract(chaincodeID);
3027
it('CreateToken', async () => {
28+
try {
29+
await contract.submitTransaction('CreateToken', JSON.stringify({Owner: 'icddMSP', MintTime: new Date()}));
30+
} catch (e) {
31+
console.error(e);
32+
}
33+
3134

3235
});
3336
});

cc/testutil.js

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as helper from '../app/helper.js';
22
import {ChaincodeDefinitionOperator} from '../app/chaincodeOperator.js';
33
import {consoleLogger} from '@davidkhala/logger/log4.js';
4+
import UserBuilder from '../common/nodejs/admin/user.js';
5+
import FabricGateway from '../common/nodejs/fabric-gateway/index.js';
46

57
const channel = 'allchannel';
68

@@ -35,3 +37,12 @@ export async function commit(org, chaincodeID, orderer, init_required = false) {
3537
await operator.queryAndCommit(chaincodeID, orderer);
3638
await operator.disconnect();
3739
}
40+
41+
export function getContract(chaincodeID) {
42+
const org = 'icdd';
43+
const peer = helper.newPeer(0, org);
44+
const user = new UserBuilder(undefined, helper.getOrgAdmin(org));
45+
46+
const gateway = new FabricGateway(peer, user);
47+
return gateway.getContract(channel, chaincodeID);
48+
}

0 commit comments

Comments
 (0)