Skip to content

Commit

Permalink
added overriding of user timestamp (hyperledger-archives#2376)
Browse files Browse the repository at this point in the history
Signed-off-by: awjh-ibm <[email protected]>
  • Loading branch information
awjh-ibm authored and bestbeforetoday committed Oct 19, 2017
1 parent 3b51118 commit 2c18aeb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
5 changes: 1 addition & 4 deletions packages/composer-client/lib/businessnetworkconnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,7 @@ class BusinessNetworkConnection extends EventEmitter {
return Util.createTransactionId(this.securityContext)
.then ((id)=>{
transaction.setIdentifier(id.idStr);
let timestamp = transaction.timestamp;
if (timestamp === null || timestamp === undefined) {
timestamp = transaction.timestamp = new Date();
}
transaction.timestamp = new Date();
let data = this.getBusinessNetwork().getSerializer().toJSON(transaction);
return Util.invokeChainCode(this.securityContext, 'submitTransaction', [JSON.stringify(data)], {transactionId:id.id});
});
Expand Down
12 changes: 7 additions & 5 deletions packages/composer-client/test/businessnetworkconnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,6 @@ describe('BusinessNetworkConnection', () => {

// Create the transaction.
const tx = factory.newResource('org.acme.sample', 'SampleTransaction', 'c89291eb-969f-4b04-b653-82deb5ee0ba1');
tx.timestamp = new Date();

// Set up the responses from the chain-code.
sandbox.stub(Util, 'invokeChainCode').resolves();
Expand Down Expand Up @@ -820,7 +819,6 @@ describe('BusinessNetworkConnection', () => {
// Create the transaction.
const tx = factory.newTransaction('org.acme.sample', 'SampleTransaction');
delete tx.$identifier;
tx.timestamp = new Date();

// Stub the UUID generator.
sandbox.stub(uuid, 'v4').returns('c89291eb-969f-4b04-b653-82deb5ee0ba1');
Expand All @@ -844,7 +842,7 @@ describe('BusinessNetworkConnection', () => {

});

it('should generate a transaction timestamp if one not specified', () => {
it('should overwrite a user passed timestamp', () => {

// Fake the transaction registry.
const txRegistry = sinon.createStubInstance(TransactionRegistry);
Expand All @@ -853,7 +851,7 @@ describe('BusinessNetworkConnection', () => {

// Create the transaction.
const tx = factory.newTransaction('org.acme.sample', 'SampleTransaction');
delete tx.timestamp;
tx.timestamp = new Date('October 24, 1994');

// Stub the UUID generator.
sandbox.stub(uuid, 'v4').returns('c89291eb-969f-4b04-b653-82deb5ee0ba1');
Expand All @@ -867,7 +865,11 @@ describe('BusinessNetworkConnection', () => {
.then(() => {

// Force the transaction to be serialized as some fake JSON.
const json = JSON.stringify(serializer.toJSON(tx));
const serialized = serializer.toJSON(tx);
const json = JSON.stringify(serialized);

// Check that timestamp was overwritten
serialized.timestamp.should.deep.equal('1970-01-01T00:00:00.000Z');

// Check that the query was made successfully.
sinon.assert.calledOnce(Util.invokeChainCode);
Expand Down

0 comments on commit 2c18aeb

Please sign in to comment.