-
Notifications
You must be signed in to change notification settings - Fork 707
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FGJ-86: Allow client to specify transaction ID (#57)
- Add Channel.newTransactionContext() to allow transaction IDs to be generated prior to sending proposals. - Add TransactionRequest.setTransactionContext() to allow pre-generated transactions IDs to be used. - Up-front validation of user context on TransactionRequest to avoid numerous checks further through the submit flow. Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
- Loading branch information
1 parent
9da9a07
commit 3b32367
Showing
11 changed files
with
208 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/test/java/org/hyperledger/fabric/sdk/TransactionRequestTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2020 IBM - All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.hyperledger.fabric.sdk; | ||
|
||
import java.util.Optional; | ||
|
||
import org.hyperledger.fabric.sdk.testutils.TestUtils; | ||
import org.hyperledger.fabric.sdk.transaction.TransactionContext; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
public class TransactionRequestTest { | ||
@Test(expected = NullPointerException.class) | ||
public void newWithNullUserThrows() { | ||
TransactionRequest request = new TransactionRequest(null); | ||
} | ||
|
||
@Test(expected = NullPointerException.class) | ||
public void testSetUserContextWithNullUserThrows() { | ||
User user = TestUtils.getMockUser("user", "mspId"); | ||
TransactionRequest request = new TransactionRequest(user); | ||
|
||
request.setUserContext(null); | ||
} | ||
|
||
@Test | ||
public void testSetTransactionContext() { | ||
User user = TestUtils.getMockUser("user", "mspId"); | ||
TransactionRequest request = new TransactionRequest(user); | ||
|
||
TransactionContext context = Mockito.mock(TransactionContext.class); | ||
Mockito.when(context.getUser()).thenReturn(user); | ||
|
||
request.setTransactionContext(context); | ||
|
||
Optional<TransactionContext> actual = request.getTransactionContext(); | ||
Assert.assertTrue("Transaction context is present", actual.isPresent()); | ||
Assert.assertEquals("Excepted context", context, actual.get()); | ||
} | ||
|
||
@Test | ||
public void testSetTransactionContextAlsoSetsUserContext() { | ||
User oldUser = TestUtils.getMockUser("oldUser", "mspId"); | ||
TransactionRequest request = new TransactionRequest(oldUser); | ||
|
||
TransactionContext context = Mockito.mock(TransactionContext.class); | ||
User newUser = TestUtils.getMockUser("newUser", "mspId"); | ||
Mockito.when(context.getUser()).thenReturn(newUser); | ||
|
||
request.setTransactionContext(context); | ||
|
||
Assert.assertEquals(newUser, request.getUserContext()); | ||
} | ||
|
||
@Test | ||
public void testSetUserContextRemovesTransactionContext() { | ||
User user = TestUtils.getMockUser("user", "mspId"); | ||
TransactionRequest request = new TransactionRequest(user); | ||
|
||
TransactionContext context = Mockito.mock(TransactionContext.class); | ||
Mockito.when(context.getUser()).thenReturn(user); | ||
request.setTransactionContext(context); | ||
|
||
request.setUserContext(user); | ||
|
||
Assert.assertFalse(request.getTransactionContext().isPresent()); | ||
} | ||
} |
Oops, something went wrong.