Skip to content

Commit

Permalink
[FAB-12567] executeTransaction to evaluateTransaction
Browse files Browse the repository at this point in the history
- Updated unit and integration tests

Change-Id: I2c83a6fe7ed808c21027d3c9edfe05ab737fb169
Signed-off-by: Liam Grace <liamgrace.896@gmail.com>
  • Loading branch information
liam-grace committed Oct 24, 2018
1 parent aa7df5e commit 74ffdf8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions fabric-network/lib/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Contract {

/**
* Submit a transaction to the ledger. The transaction function <code>transactionName</code>
* will be executed on the endorsing peers and then submitted to the ordering service
* will be evaluated on the endorsing peers and then submitted to the ordering service
* for committing to the ledger.
* @param {string} transactionName Transaction function name
* @param {...string} parameters Transaction function parameters
Expand Down Expand Up @@ -201,20 +201,20 @@ class Contract {
}

/**
* Execute a transaction function and return its results.
* Evaluate a transaction function and return its results.
* The transaction function <code>transactionName</code>
* will be executed on the endorsing peers but the responses will not be sent to to
* will be evaluated on the endorsing peers but the responses will not be sent to to
* the ordering service and hence will not be committed to the ledger.
* This is used for querying the world state.
* @param {string} transactionName Transaction function name
* @param {...string} parameters Transaction function parameters
* @returns {Buffer} Payload response from the transaction function
*/
async executeTransaction(transactionName, ...parameters) {
async evaluateTransaction(transactionName, ...parameters) {

// form the transaction name with the namespace
const fullTxName = (this.namespace==='') ? transactionName : `${this.namespace}:${transactionName}`;
this._verifyTransactionDetails('executeTransaction', fullTxName, parameters);
this._verifyTransactionDetails('evaluateTransaction', fullTxName, parameters);
const txId = this.gateway.getClient().newTransactionID();
const result = await this.queryHandler.queryChaincode(this.chaincodeId, txId, fullTxName, parameters);
return result ? result : null;
Expand Down
10 changes: 5 additions & 5 deletions fabric-network/test/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,11 @@ describe('Contract', () => {

});

describe('#executeTransaction', () => {
describe('#evaluateTransaction', () => {
it('should query chaincode and handle a good response without return data', async () => {
mockQueryHandler.queryChaincode.withArgs('someid', mockTransactionID, 'myfunc', ['arg1', 'arg2']).resolves();

const result = await contract.executeTransaction('myfunc', 'arg1', 'arg2');
const result = await contract.evaluateTransaction('myfunc', 'arg1', 'arg2');
sinon.assert.calledOnce(mockQueryHandler.queryChaincode);
should.equal(result, null);
});
Expand All @@ -295,15 +295,15 @@ describe('Contract', () => {
const response = Buffer.from('hello world');
mockQueryHandler.queryChaincode.withArgs('someid', mockTransactionID, 'myfunc', ['arg1', 'arg2']).resolves(response);

const result = await contract.executeTransaction('myfunc', 'arg1', 'arg2');
const result = await contract.evaluateTransaction('myfunc', 'arg1', 'arg2');
sinon.assert.calledOnce(mockQueryHandler.queryChaincode);
result.equals(response).should.be.true;
});

it('should query chaincode and handle an error response', () => {
const response = new Error('such error');
mockQueryHandler.queryChaincode.withArgs('someid', mockTransactionID, 'myfunc', ['arg1', 'arg2']).rejects(response);
return contract.executeTransaction('myfunc', 'arg1', 'arg2')
return contract.evaluateTransaction('myfunc', 'arg1', 'arg2')
.should.be.rejectedWith(/such error/);

});
Expand All @@ -313,7 +313,7 @@ describe('Contract', () => {

mockQueryHandler.queryChaincode.withArgs('someid', mockTransactionID, 'myfunc', ['arg1', 'arg2']).resolves();

await nscontract.executeTransaction('myfunc', 'arg1', 'arg2');
await nscontract.evaluateTransaction('myfunc', 'arg1', 'arg2');
sinon.assert.calledOnce(mockQueryHandler.queryChaincode);
sinon.assert.calledWith(mockQueryHandler.queryChaincode,
sinon.match.any,
Expand Down
2 changes: 1 addition & 1 deletion fabric-network/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class Network {
}

export class Contract {
executeTransaction(transactionName: string, ...parameters: string[]): Promise<Buffer>;
evaluateTransaction(transactionName: string, ...parameters: string[]): Promise<Buffer>;
submitTransaction(transactionName: string, ...parameters: string[]): Promise<Buffer>;
}

Expand Down
8 changes: 4 additions & 4 deletions test/integration/network-e2e/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const testUtils = require('../../unit/util.js');
const channelName = testUtils.NETWORK_END2END.channel;
const chaincodeId = testUtils.NETWORK_END2END.chaincodeId;

test('\n\n***** Network End-to-end flow: execute transaction to get information *****\n\n', async (t) => {
test('\n\n***** Network End-to-end flow: evaluate transaction to get information *****\n\n', async (t) => {
const tmpdir = path.join(os.tmpdir(), 'integration-network-test988');
const gateway = new Gateway();

Expand Down Expand Up @@ -61,11 +61,11 @@ test('\n\n***** Network End-to-end flow: execute transaction to get information

const contract = await channel.getContract(chaincodeId);

t.pass('Got the contract, about to execute (query) transaction');
t.pass('Got the contract, about to evaluate (query) transaction');


// try a standard query
const responseBuffer = await contract.executeTransaction('query', 'a');
const responseBuffer = await contract.evaluateTransaction('query', 'a');
let response = responseBuffer.toString();

if(response * 1 === parseInt(response)){
Expand All @@ -77,7 +77,7 @@ test('\n\n***** Network End-to-end flow: execute transaction to get information

// check we deal with an error returned.
try {
response = await contract.executeTransaction('throwError', 'a', 'b','100');
response = await contract.evaluateTransaction('throwError', 'a', 'b','100');
t.fail('Transaction "throwError" should have thrown an error. Got response: ' + response.toString());
} catch(expectedErr) {
if(expectedErr.message.includes('throwError: an error occurred')) {
Expand Down
2 changes: 1 addition & 1 deletion test/typescript/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ import {
const contract: Contract = await network.getContract('chaincode');

let response: Buffer = await contract.submitTransaction('move', 'a', 'b','100');
response = await contract.executeTransaction('move', 'a', 'b','100');
response = await contract.evaluateTransaction('move', 'a', 'b','100');

const aClient: Client = gateway.getClient();
const user: User = gateway.getCurrentIdentity();
Expand Down

0 comments on commit 74ffdf8

Please sign in to comment.