Skip to content

Commit

Permalink
Transaction metadata tags updated (#265)
Browse files Browse the repository at this point in the history
Signed-off-by: Kestutis Gudynas <44440041+kemi04@users.noreply.github.com>
  • Loading branch information
kemi04 authored Mar 23, 2021
1 parent ea8da64 commit 9b80078
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 20 deletions.
3 changes: 3 additions & 0 deletions apis/fabric-contract-api/lib/annotations/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ module.exports.Transaction = function Transaction (commit = true) {

const tag = [];
if (commit) {
tag.push('SUBMIT');
tag.push('submitTx');
} else {
tag.push('EVALUATE');
}

utils.appendOrUpdate(transactions, 'name', propertyKey, {
Expand Down
3 changes: 3 additions & 0 deletions apis/fabric-contract-api/schema/example-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
}
],
"tag": [
"SUBMIT",
"submitTx"
]
},
Expand Down Expand Up @@ -157,6 +158,7 @@
}
],
"tag": [
"SUBMIT",
"submitTx"
]
},
Expand Down Expand Up @@ -209,6 +211,7 @@
}
],
"tag": [
"SUBMIT",
"submitTx"
]
}
Expand Down
4 changes: 4 additions & 0 deletions apis/fabric-contract-api/schema/helloworld.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
"transactions": [
{
"tag": [
"SUBMIT",
"submitTx"
],
"parameters": [],
"name": "instantiate"
},
{
"tag": [
"SUBMIT",
"submitTx"
],
"parameters": [
Expand All @@ -30,6 +32,7 @@
},
{
"tag": [
"SUBMIT",
"submitTx"
],
"parameters": [
Expand All @@ -54,6 +57,7 @@
],
"name": "getGreeting",
"tag": [
"SUBMIT",
"submitTx"
],
"parameters": []
Expand Down
20 changes: 10 additions & 10 deletions apis/fabric-contract-api/test/unit/annotations/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('Transaction.js', () => {

const getMetadataStub = sandbox.stub(Reflect, 'getMetadata').onFirstCall().returns([{
name: 'someTransaction',
tag: ['submitTx']
tag: ['SUBMIT', 'submitTx']
}]).onSecondCall().returns([
MockContext,
'some type',
Expand All @@ -100,10 +100,10 @@ describe('Transaction.js', () => {
sinon.assert.calledOnce(defineMetadataStub);
sinon.assert.calledWith(defineMetadataStub, 'fabric:transactions', [{
name: 'someTransaction',
tag: ['submitTx'],
tag: ['SUBMIT', 'submitTx'],
}, {
name: 'mockKey',
tag: ['submitTx'],
tag: ['SUBMIT', 'submitTx'],
parameters: [
{
name: 'param1',
Expand All @@ -122,7 +122,7 @@ describe('Transaction.js', () => {

sandbox.stub(Reflect, 'getMetadata').onFirstCall().returns([{
name: 'someTransaction',
tag: ['submitTx']
tag: ['SUBMIT', 'submitTx']
}]).onSecondCall().returns([
MockContext,
'Object'
Expand All @@ -140,7 +140,7 @@ describe('Transaction.js', () => {
it ('should handle existing transactions of which matches name and already has param metadata', () => {
const transactions = [{
name: 'mockKey',
tag: ['submitTx'],
tag: ['SUBMIT', 'submitTx'],
parameters: [{
name: 'param1',
schema: 'some special schema',
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('Transaction.js', () => {
sinon.assert.calledOnce(defineMetadataStub);
sinon.assert.calledWith(defineMetadataStub, 'fabric:transactions', [{
name: 'mockKey',
tag: ['submitTx'],
tag: ['SUBMIT', 'submitTx'],
parameters: [
{
name: 'param1',
Expand Down Expand Up @@ -226,7 +226,7 @@ describe('Transaction.js', () => {
sinon.assert.calledOnce(defineMetadataStub);
sinon.assert.calledWith(defineMetadataStub, 'fabric:transactions', [{
name: 'mockKey',
tag: ['submitTx'],
tag: ['SUBMIT', 'submitTx'],
parameters: []
}], mockTarget);
});
Expand All @@ -250,7 +250,7 @@ describe('Transaction.js', () => {
sinon.assert.calledOnce(defineMetadataStub);
sinon.assert.calledWith(defineMetadataStub, 'fabric:transactions', [{
name: 'mockKey',
tag: [],
tag: ["EVALUATE"],
parameters: []
}], mockTarget);
});
Expand All @@ -266,7 +266,7 @@ describe('Transaction.js', () => {
it ('should handle existing transactions', () => {
const getMetadataStub = sandbox.stub(Reflect, 'getMetadata').returns([{
name: 'someTransaction',
tag: ['submitTx'],
tag: ['SUBMIT', 'submitTx'],
parameters: []
}]);

Expand All @@ -280,7 +280,7 @@ describe('Transaction.js', () => {
sinon.assert.calledOnce(defineMetadataStub);
sinon.assert.calledWith(defineMetadataStub, 'fabric:transactions', [{
name: 'someTransaction',
tag: ['submitTx'],
tag: ['SUBMIT', 'submitTx'],
parameters: []
}, {
name: 'mockKey',
Expand Down
12 changes: 12 additions & 0 deletions apis/fabric-contract-api/test/unit/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"transactions": [
{
"tag": [
"SUBMIT",
"submitTx"
],
"parameters": [],
Expand All @@ -22,6 +23,7 @@
},
{
"tag": [
"SUBMIT",
"submitTx"
],
"parameters": [
Expand All @@ -37,6 +39,7 @@
},
{
"tag": [
"SUBMIT",
"submitTx"
],
"parameters": [
Expand Down Expand Up @@ -89,6 +92,7 @@
"transactions": [
{
"tag": [
"SUBMIT",
"submitTx"
],
"parameters": [],
Expand All @@ -101,6 +105,7 @@
},
{
"tag": [
"SUBMIT",
"submitTx"
],
"parameters": [
Expand All @@ -116,6 +121,7 @@
},
{
"tag": [
"SUBMIT",
"submitTx"
],
"parameters": [
Expand Down Expand Up @@ -168,6 +174,7 @@
"transactions": [
{
"tag": [
"SUBMIT",
"submitTx"
],
"parameters": [],
Expand All @@ -180,6 +187,7 @@
},
{
"tag": [
"SUBMIT",
"submitTx"
],
"parameters": [
Expand All @@ -195,6 +203,7 @@
},
{
"tag": [
"SUBMIT",
"submitTx"
],
"parameters": [
Expand Down Expand Up @@ -247,6 +256,7 @@
"transactions": [
{
"tag": [
"SUBMIT",
"submitTx"
],
"parameters": [],
Expand All @@ -259,6 +269,7 @@
},
{
"tag": [
"SUBMIT",
"submitTx"
],
"parameters": [
Expand All @@ -274,6 +285,7 @@
},
{
"tag": [
"SUBMIT",
"submitTx"
],
"parameters": [
Expand Down
4 changes: 2 additions & 2 deletions docs/_jsdoc/tutorials/annotated-contract-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ A starting example is a very simple transaction function.
{
"name": "setGreetingText",
"tag": [
"submitTx"
"SUBMIT", "submitTx"
],
"parameters": [
{
Expand All @@ -161,7 +161,7 @@ A starting example is a very simple transaction function.
```

- the name of the function is 'setGreetingText'
- it has a tag of 'submitTx' that means that this transaction is intended to be submitted with the 'submitTransaction' sdk function. The implication is that this is then submitted to the orderder. If this is not present, then the function will be 'evaluated', not submitted to the order so in effect a query-style operation.
- it has tags of 'SUBMIT' and 'submitTx' that means that this transaction is intended to be submitted with the 'submitTransaction' sdk function. The implication is that this is then submitted to the orderder. If this is not present, then the function will be 'evaluated', not submitted to the order so in effect a query-style operation.
- the parameters of the function are defined in 'parameters' as an array of parameter definitions. (each of which follows the [parameterObject](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#parameterObject) of OpenAPI)
- typically a parameter will contain a 'name', optional 'description' and critically the 'schema'
- again 'schema' comes from OpenAPI [schemaObject](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#schemaObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class ChaincodeFromContract {
};

if (contract.getName() !== 'org.hyperledger.fabric') {
transaction.tags = ['submitTx'];
transaction.tags = ['SUBMIT', 'submitTx'];
}

// add 'argN' parameters, skipping the first (stub) parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ describe('chaincodefromcontract', () => {
{
returns: {name: 'success', schema: {type: 'string'}},
name: 'fn',
tag: ['submitTx'],
tag: ['SUBMIT', 'submitTx'],
parameters: []
},
]
Expand Down Expand Up @@ -1035,7 +1035,7 @@ describe('chaincodefromcontract', () => {
}
}
],
tags: ['submitTx']
tags: ['SUBMIT', 'submitTx']
}]);

delete Object.getPrototypeOf(ci).property;
Expand Down Expand Up @@ -1071,7 +1071,7 @@ describe('chaincodefromcontract', () => {
}
}
],
tags: ['submitTx']
tags: ['SUBMIT', 'submitTx']
}]);

delete Object.getPrototypeOf(ci).property;
Expand Down Expand Up @@ -1154,11 +1154,11 @@ describe('chaincodefromcontract', () => {
}
}
],
tags: ['submitTx']
tags: ['SUBMIT', 'submitTx']
},
{
name: 'conga',
tags: ['submitTx']
tags: ['SUBMIT', 'submitTx']
}
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"transactions": [
{
"tag": [
"SUBMIT",
"submitTx"
],
"parameters": [
Expand Down Expand Up @@ -53,6 +54,7 @@
},
{
"tag": [
"SUBMIT",
"submitTx"
],
"parameters": [
Expand All @@ -71,7 +73,7 @@
"$ref": "#/components/schemas/Asset"
},
"name": "getAsset",
"tag": [],
"tag": ["EVALUATE"],
"parameters": [
{
"name": "id",
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const queryFunctions = async () => {

const metadata = JSON.parse(stdout);

const expectedMetadata = '{"$schema":"https://hyperledger.github.io/fabric-chaincode-node/main/api/contract-schema.json","contracts":{"UpdateValues":{"name":"UpdateValues","contractInstance":{"name":"UpdateValues","logBuffer":{"output":[]},"default":true},"transactions":[{"name":"setup","tags":["submitTx"]},{"name":"setNewAssetValue","tags":["submitTx"],"parameters":[{"name":"arg0","description":"Argument 0","schema":{"type":"string"}}]},{"name":"doubleAssetValue","tags":["submitTx"]}],"info":{"title":"","version":""}},"RemoveValues":{"name":"RemoveValues","contractInstance":{"name":"RemoveValues"},"transactions":[{"name":"quarterAssetValue","tags":["submitTx"]},{"name":"getAssetValue","tags":["submitTx"]}],"info":{"title":"","version":""}},"org.hyperledger.fabric":{"name":"org.hyperledger.fabric","contractInstance":{"name":"org.hyperledger.fabric"},"transactions":[{"name":"GetMetadata"}],"info":{"title":"","version":""}}},"info":{"version":"1.0.0","title":"chaincode"},"components":{"schemas":{}}}';
const expectedMetadata = '{"$schema":"https://hyperledger.github.io/fabric-chaincode-node/main/api/contract-schema.json","contracts":{"UpdateValues":{"name":"UpdateValues","contractInstance":{"name":"UpdateValues","logBuffer":{"output":[]},"default":true},"transactions":[{"name":"setup","tags":["SUBMIT","submitTx"]},{"name":"setNewAssetValue","tags":["SUBMIT","submitTx"],"parameters":[{"name":"arg0","description":"Argument 0","schema":{"type":"string"}}]},{"name":"doubleAssetValue","tags":["SUBMIT","submitTx"]}],"info":{"title":"","version":""}},"RemoveValues":{"name":"RemoveValues","contractInstance":{"name":"RemoveValues"},"transactions":[{"name":"quarterAssetValue","tags":["SUBMIT","submitTx"]},{"name":"getAssetValue","tags":["SUBMIT","submitTx"]}],"info":{"title":"","version":""}},"org.hyperledger.fabric":{"name":"org.hyperledger.fabric","contractInstance":{"name":"org.hyperledger.fabric"},"transactions":[{"name":"GetMetadata"}],"info":{"title":"","version":""}}},"info":{"version":"1.0.0","title":"chaincode"},"components":{"schemas":{}}}';

const schema = fs.readFileSync(path.join(__dirname, '../../apis/fabric-contract-api/schema/contract-schema.json'));

Expand Down

0 comments on commit 9b80078

Please sign in to comment.