diff --git a/build.gradle b/build.gradle index aa0fb5e..3ee1912 100644 --- a/build.gradle +++ b/build.gradle @@ -33,10 +33,6 @@ allprojects { cordaRuntimePluginWorkspaceDir = "workspace" cordaBinDir = "${System.getProperty("user.home")}/.corda/corda5" cordaCliBinDir = "${System.getProperty("user.home")}/.corda/cli" - - // Only need to supply these if you want to use an unpublished version - artifactoryUsername = findProperty('cordaArtifactoryUsername') ?: System.getenv('CORDA_ARTIFACTORY_USERNAME') - artifactoryPassword = findProperty('cordaArtifactoryPassword') ?: System.getenv('CORDA_ARTIFACTORY_PASSWORD') } java { @@ -58,22 +54,6 @@ allprojects { // All dependencies are held in Maven Central mavenLocal() mavenCentral() - - // R3 Internal repositories for dev - // Repository provides Corda 5 binaries that implement Corda-API. - // These will be made publicly available. - // Final location to be decided. - // Repository subject to change - maven { - url = "$artifactoryContextUrl/corda-os-maven" - authentication { - basic(BasicAuthentication) - } - credentials { - username = findProperty('cordaArtifactoryUsername') ?: System.getenv('CORDA_ARTIFACTORY_USERNAME') - password = findProperty('cordaArtifactoryPassword') ?: System.getenv('CORDA_ARTIFACTORY_PASSWORD') - } - } } tasks.withType(Test).configureEach { diff --git a/config/combined-worker-compose.yaml b/config/combined-worker-compose.yaml index 3cfdacc..0eb63bf 100644 --- a/config/combined-worker-compose.yaml +++ b/config/combined-worker-compose.yaml @@ -49,7 +49,7 @@ services: ] corda: - image: corda-os-docker.software.r3.com/corda-os-combined-worker-kafka:5.2.0.0-RC02 + image: corda/corda-os-combined-worker-kafka:5.2.0.0 depends_on: - postgresql - kafka diff --git a/contracts/src/test/java/com/r3/developers/apples/contracts/AppleStampContractIssueCommandTest.java b/contracts/src/test/java/com/r3/developers/apples/contracts/AppleStampContractIssueCommandTest.java deleted file mode 100644 index 08f73ef..0000000 --- a/contracts/src/test/java/com/r3/developers/apples/contracts/AppleStampContractIssueCommandTest.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.r3.developers.apples.contracts; - -import com.r3.developers.apples.states.AppleStamp; -import net.corda.v5.ledger.utxo.Command; -import net.corda.v5.ledger.utxo.transaction.UtxoSignedTransaction; -import org.junit.jupiter.api.Test; - -/** - * This class is an implementation of the ApplesContractTest which implements the ContractTest abstract class. - * The ContractTest class provides functions to easily perform unit tests on contracts. - * The ApplesContractTest adds additional default values for states as well as helper functions to make utxoLedgerTransactions. - * This allows us to test our implementation of contracts without having to trigger a workflow. - **/ - -// This specific class is involved with testing the scenarios involving the AppleStamp state and the AppleCommands.Issue command. -public class AppleStampContractIssueCommandTest extends ApplesContractTest { - - /** - * All Tests must start with the @Test annotation. Tests can be run individually by running them with your IDE. - * Alternatively, tests can be grouped up and tested by running the test from the line defining the class above. - * If you need help to write tests, think of a happy path scenario and then think of every line of code in the contract - * where the transaction could fail. - * It helps to meaningfully name tests so that you know exactly what success case or specific error you are testing for. - **/ - - @Test - public void happyPath() { - // The following test builds a transaction that should pass all the contract verification checks. - // The buildTransaction function helps create a utxoLedgerTransaction that can be referenced for contract tests - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState(outputAppleStampState) - .addCommand(new AppleCommands.Issue()) - .addSignatories(outputAppleStampStateParticipants) - .toSignedTransaction(); - /** - * The assertVerifies function is the general way to test if a contract test passes or fails a transaction. - * If the transaction is verified, then it means that the contract tests pass. - **/ - assertVerifies(transaction); - } - - @Test - public void outputContractStateSizeNotOne() { - // The following test builds a transaction that would fail due to not meeting the expectation that a transaction - // in this CorDapp for this state should only contain one output state. - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState(outputAppleStampState) - .addOutputState(outputAppleStampState) - .addCommand(new AppleCommands.Issue()) - .addSignatories(outputAppleStampStateParticipants) - .toSignedTransaction(); - /** - * The assertFailsWith function is the general way to test for unhappy path test cases contract tests. - * - * The transaction defined above will fail because the contract expects only one output state. However, we built - * a transaction with two output states. So we expect the transaction to fail, and only 'pass' our test if we - * can match the error message we expect. - * - * NOTE: the assertFailsWith method tests if the exact string of the error message matches the expected message - * to test if the string of the error message contains a substring within the error message, use the - * assertFailsWithMessageContaining() function using the same arguments. - **/ - assertFailsWith(transaction, "This transaction should only have one AppleStamp state as output"); - } - - @Test - public void blankStampDescription() { - // The following test builds a transaction that would fail due to having an empty stamp description string - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState( - // Where a specific piece of test data is used only once, it makes sense to create it within the test - // rather than at a class/parent class level. - new AppleStamp( - outputAppleStampStateId, - "", - outputAppleStampStateIssuer, - outputAppleStampStateHolder, - outputAppleStampStateParticipants - ) - ) - .addCommand(new AppleCommands.Issue()) - .addSignatories(outputAppleStampStateParticipants) - .toSignedTransaction(); - assertFailsWith(transaction, "The output AppleStamp state should have clear description of the type of redeemable goods"); - } - - @Test - public void missingCommand() { - // The following test builds a transaction that would fail due to not having a command. - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState(outputAppleStampState) - .addSignatories(outputAppleStampStateParticipants) - .toSignedTransaction(); - assertFailsWith(transaction, "Index 0 out of bounds for length 0"); - } - - @Test - public void unknownCommand() { - // The following test builds a transaction that would fail due to providing an invalid command. - class DummyCommand implements Command { - } - - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState(outputAppleStampState) - .addCommand(new DummyCommand()) - .addSignatories(outputAppleStampStateParticipants) - .toSignedTransaction(); - assertFailsWith(transaction, "Incorrect type of AppleStamp commands: " + - "class com.r3.developers.apples.contracts.AppleStampContractIssueCommandTest$1DummyCommand"); - } -} \ No newline at end of file diff --git a/contracts/src/test/java/com/r3/developers/apples/contracts/ApplesContractTest.java b/contracts/src/test/java/com/r3/developers/apples/contracts/ApplesContractTest.java deleted file mode 100644 index 9d49aef..0000000 --- a/contracts/src/test/java/com/r3/developers/apples/contracts/ApplesContractTest.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.r3.developers.apples.contracts; - -import com.r3.corda.ledger.utxo.testing.ContractTest; -import com.r3.developers.apples.states.AppleStamp; -import com.r3.developers.apples.states.BasketOfApples; -import net.corda.v5.ledger.utxo.StateAndRef; -import net.corda.v5.ledger.utxo.transaction.UtxoSignedTransaction; -import java.security.PublicKey; -import java.util.List; -import java.util.UUID; - -/** - * The following is the base implementation of the Contract Tests for the Apples CorDapp-template-tutorial. - * - * - The AppleContractTest abstract class implements the ContractTest class. - * - For full contract test coverage, we generally create a class for every command scenario for every state. - * - Each of these classes will implement the abstract class to incorporate ContractTest general testing functionality - * as well as the functionality specific for this CordApp tutorial example. - * - * In this case, we have 3 scenarios (you can refer to contract files for the apples tutorial): - * 1. AppleStamp state, AppleCommands.Issue command - * 2. BasketOfApples state, AppleCommand.PackBasket command - * 3. BasketOfApples state, AppleCommand.Redeem command - * - * The variables and methods within this abstract class are written to enable code re-use such that states are set up - * automatically so that you only need to worry about the logic of your contracts - **/ - -public abstract class ApplesContractTest extends ContractTest { - - /** - * The following are implementations of default values for the AppleStamp state for contract testing. - * Some values such as the public keys already have default values implemented by the ContractTest class. - * for more information, navigate to their declaration - */ - - // Default values for AppleStamp state - protected UUID outputAppleStampStateId = UUID.randomUUID(); - protected String outputAppleStampStateStampDesc = "Can be exchanged for a single basket of apples"; - protected PublicKey outputAppleStampStateIssuer = bobKey; - protected PublicKey outputAppleStampStateHolder = daveKey; - protected List outputAppleStampStateParticipants = List.of(bobKey, daveKey); - protected AppleStamp outputAppleStampState = new AppleStamp( - outputAppleStampStateId, - outputAppleStampStateStampDesc, - outputAppleStampStateIssuer, - outputAppleStampStateHolder, - outputAppleStampStateParticipants - ); - - // Default values for BasketOfApples state - protected String outputBasketOfApplesStateDescription = "Golden delicious apples, picked on 11th May 2023"; - protected PublicKey outputBasketOfApplesStateFarm = bobKey; - protected PublicKey outputBasketOfApplesStateOwner = bobKey; - protected int outputBasketOfApplesStateWeight = 214; - protected List outputBasketOfApplesStateParticipants = List.of(bobKey); - protected BasketOfApples outputBasketOfApplesState = new BasketOfApples( - outputBasketOfApplesStateDescription, - outputBasketOfApplesStateFarm, - outputBasketOfApplesStateOwner, - outputBasketOfApplesStateWeight, - outputBasketOfApplesStateParticipants - ); - - // Helper function to create input AppleStamp state when building a transaction for contract testing. - // The argument for outputState for this and the next helper function is set to the default apple state for happy path scenarios. - // To capture negative test cases or other edge cases, they are written within individual tests. - @SuppressWarnings("unchecked") - protected StateAndRef createInputStateAppleStamp(AppleStamp outputState) { - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState(outputState) - .addCommand(new AppleCommands.Issue()) - .addSignatories(outputState.getParticipants()) - .toSignedTransaction(); - transaction.toLedgerTransaction(); - return (StateAndRef) transaction.getOutputStateAndRefs().get(0); - } - - // Helper function to create input BasketOfApples state when building a transaction for contract testing. - @SuppressWarnings("unchecked") - protected StateAndRef createInputStateBasketOfApples(BasketOfApples outputState) { - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState(outputState) - .addCommand(new AppleCommands.PackBasket()) - .addSignatories(outputState.getParticipants()) - .toSignedTransaction(); - transaction.toLedgerTransaction(); - return (StateAndRef) transaction.getOutputStateAndRefs().get(0); - } -} \ No newline at end of file diff --git a/contracts/src/test/java/com/r3/developers/apples/contracts/BasketOfApplesContractPackBasketCommandTest.java b/contracts/src/test/java/com/r3/developers/apples/contracts/BasketOfApplesContractPackBasketCommandTest.java deleted file mode 100644 index 7fcccdd..0000000 --- a/contracts/src/test/java/com/r3/developers/apples/contracts/BasketOfApplesContractPackBasketCommandTest.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.r3.developers.apples.contracts; - -import com.r3.developers.apples.states.BasketOfApples; -import net.corda.v5.ledger.utxo.Command; -import net.corda.v5.ledger.utxo.transaction.UtxoSignedTransaction; -import org.junit.jupiter.api.Test; - -/** - * This class is an implementation of the ApplesContractTest which implements the ContractTest abstract class. - * The ContractTest class provides functions to easily perform unit tests on contracts. - * The ApplesContractTest adds additional default values for states as well as helper functions to make utxoLedgerTransactions. - * This allows us to test our implementation of contracts without having to trigger a workflow. - **/ - -// This specific class is involved with testing the scenarios involving the BasketOfApples state and the AppleCommands.PackBasket command. -public class BasketOfApplesContractPackBasketCommandTest extends ApplesContractTest { - - /** - * All Tests must start with the @Test annotation. Tests can be run individually by running them with your IDE. - * Alternatively, tests can be grouped up and tested by running the test from the line defining the class above. - * If you need help to write tests, think of a happy path scenario and then think of every line of code in the contract - * where the transaction could fail. - * It helps to meaningfully name tests so that you know exactly what success case or specific error you are testing for. - **/ - - @Test - public void happyPath() { - // The following test builds a transaction that should pass all the contract verification checks. - // The buildTransaction function helps create a utxoLedgerTransaction that can be referenced for contract tests. - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState(outputBasketOfApplesState) - .addCommand(new AppleCommands.PackBasket()) - .addSignatories(outputBasketOfApplesStateParticipants) - .toSignedTransaction(); - /** - * The assertVerifies function is the general way to test if a contract test passes or fails a transaction. - * If the transaction is verified, then it means that the contract tests pass. - **/ - assertVerifies(transaction); - } - - @Test - public void outputContractStateSizeNoteOne() { - // The following test builds a transaction that would fail due to not meeting the expectation that a transaction - // in this CorDapp for this state should only contain one output state. - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState(outputBasketOfApplesState) - .addOutputState(outputBasketOfApplesState) - .addCommand(new AppleCommands.PackBasket()) - .addSignatories(outputBasketOfApplesStateParticipants) - .toSignedTransaction(); - /** - * The assertFailsWith function is the general way to test for unhappy path test cases contract tests. - * - * The transaction defined above will fail because the contract expects only one output state. However, we built - * a transaction with two output states. So we expect the transaction to fail, and only 'pass' our test if we - * can match the error message we expect. - * - * NOTE: the assertFailsWith method tests if the exact string of the error message matches the expected message - * to test if the string of the error message contains a substring within the error message, use the - * assertFailsWithMessageContaining() function using the same arguments. - **/ - assertFailsWith(transaction, "This transaction should only output one BasketOfApples state"); - } - - @Test - public void blankDescription() { - // The following test builds a transaction that would fail due to having an empty stamp description string. - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState( - new BasketOfApples( - "", - outputBasketOfApplesStateFarm, - outputBasketOfApplesStateOwner, - outputBasketOfApplesStateWeight, - outputBasketOfApplesStateParticipants - ) - ) - .addCommand(new AppleCommands.PackBasket()) - .addSignatories(outputBasketOfApplesStateParticipants) - .toSignedTransaction(); - assertFailsWith(transaction, "The output BasketOfApples state should have clear description of Apple product"); - } - - @Test - public void basketWeightIsZero() { - // The following test builds a transaction that would fail due to having a weight not greater than 0 - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState( - new BasketOfApples( - outputBasketOfApplesStateDescription, - outputBasketOfApplesStateFarm, - outputBasketOfApplesStateOwner, - 0, - outputBasketOfApplesStateParticipants - ) - ) - .addCommand(new AppleCommands.PackBasket()) - .addSignatories(outputBasketOfApplesStateParticipants) - .toSignedTransaction(); - assertFailsWith(transaction, "The output BasketOfApples state should have non zero weight"); - } - - @Test - public void basketWeightIsNegative() { - // The following test builds a transaction that would fail due to having a weight not greater than 0 - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState( - new BasketOfApples( - outputBasketOfApplesStateDescription, - outputBasketOfApplesStateFarm, - outputBasketOfApplesStateOwner, - -1, - outputBasketOfApplesStateParticipants - ) - ) - .addCommand(new AppleCommands.PackBasket()) - .addSignatories(outputBasketOfApplesStateParticipants) - .toSignedTransaction(); - assertFailsWith(transaction, "The output BasketOfApples state should have non zero weight"); - } - - @Test - public void missingCommand() { - // The following test builds a transaction that would fail due to not having a command. - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState(outputBasketOfApplesState) - .addSignatories(outputBasketOfApplesStateParticipants) - .toSignedTransaction(); - assertFailsWith(transaction, "Index 0 out of bounds for length 0"); - } - - @Test - public void unknownCommand() { - // The following test builds a transaction that would fail due to providing an invalid command. - class DummyCommand implements Command { - } - - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState(outputBasketOfApplesState) - .addCommand(new DummyCommand()) - .addSignatories(outputBasketOfApplesStateParticipants) - .toSignedTransaction(); - assertFailsWith(transaction, "Incorrect type of BasketOfApples commands: " + - "class com.r3.developers.apples.contracts.BasketOfApplesContractPackBasketCommandTest$1DummyCommand"); - } -} \ No newline at end of file diff --git a/contracts/src/test/java/com/r3/developers/apples/contracts/BasketOfApplesContractRedeemCommandTest.java b/contracts/src/test/java/com/r3/developers/apples/contracts/BasketOfApplesContractRedeemCommandTest.java deleted file mode 100644 index 7614759..0000000 --- a/contracts/src/test/java/com/r3/developers/apples/contracts/BasketOfApplesContractRedeemCommandTest.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.r3.developers.apples.contracts; - -import com.r3.developers.apples.states.AppleStamp; -import com.r3.developers.apples.states.BasketOfApples; -import net.corda.v5.ledger.utxo.StateAndRef; -import net.corda.v5.ledger.utxo.transaction.UtxoSignedTransaction; -import org.junit.jupiter.api.Test; -import java.util.List; - -/** - * This class is an implementation of the ApplesContractTest which implements the ContractTest abstract class. - * The ContractTest class provides functions to easily perform unit tests on contracts. - * The ApplesContractTest adds additional default values for states as well as helper functions to make utxoLedgerTransactions. - * This allows us to test our implementation of contracts without having to trigger a workflow. - **/ - -// This specific class is involved with testing the scenarios involving the BasketOfApples state and the AppleCommands.Redeem command. -public class BasketOfApplesContractRedeemCommandTest extends ApplesContractTest { - - /** - * All Tests must start with the @Test annotation. Tests can be run individually by running them with your IDE. - * Alternatively, tests can be grouped up and tested by running the test from the line defining the class above. - * If you need help to write tests, think of a happy path scenario and then think of every line of code in the contract - * where the transaction could fail. - * It helps to meaningfully name tests so that you know exactly what success case or specific error you are testing for. - **/ - - @Test - public void happyPath() { - // The following test builds a transaction that should pass all the contract verification checks. - // The buildTransaction function helps create a utxoLedgerTransaction that can be referenced for contract tests - - // Notice the use of the helper functions written in ApplesContractTest to help build the transaction. - // This is because we need to refer to the state reference of an input state, which is not so easy to repeatably - // make without helper functions. - StateAndRef inputAppleStampState = createInputStateAppleStamp(outputAppleStampState); - StateAndRef inputBasketOfApplesStates = createInputStateBasketOfApples(outputBasketOfApplesState); - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addInputStates(List.of(inputAppleStampState.getRef(), inputBasketOfApplesStates.getRef())) - .addOutputState(outputBasketOfApplesState) - .addCommand(new AppleCommands.Redeem()) - .addSignatories(outputBasketOfApplesStateParticipants) - .toSignedTransaction(); - /** - * The assertVerifies function is the general way to test if a contract test passes or fails a transaction. - * If the transaction is verified, then it means that the contract tests pass. - **/ - assertVerifies(transaction); - } - - @Test - public void inputContractStateSizeNotTwo() { - // The following test builds a transaction that would fail due to not meeting the expectation that a transaction - // in this CorDapp for this state should consume exactly two input states. - StateAndRef inputAppleStampState = createInputStateAppleStamp(outputAppleStampState); - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addInputStates(inputAppleStampState.getRef()) - .addOutputState(outputBasketOfApplesState) - .addCommand(new AppleCommands.Redeem()) - .addSignatories(outputBasketOfApplesStateParticipants) - .toSignedTransaction(); - /** - * The assertFailsWith function is the general way to test for unhappy path test cases contract tests. - * - * The transaction defined above will fail because the contract expects two input states. However, we built - * a transaction with one input states. So we expect the transaction to fail, and only 'pass' our test if we - * can match the error message we expect. - * - * NOTE: the assertFailsWith method tests if the exact string of the error message matches the expected message - * to test if the string of the error message contains a substring within the error message, use the - * assertFailsWithMessageContaining() function using the same arguments. - **/ - assertFailsWith(transaction, "This transaction should consume two states"); - } - - @Test - public void twoAppleStampStateInputs() { - // The following test builds a transaction that would fail due to not meeting the expectation that a transaction - // must contain exactly one AppleStamp state and one BasketOfApplesState state. - StateAndRef inputAppleStampState = createInputStateAppleStamp(outputAppleStampState); - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addInputStates(List.of(inputAppleStampState.getRef(), inputAppleStampState.getRef())) - .addOutputState(outputBasketOfApplesState) - .addCommand(new AppleCommands.Redeem()) - .addSignatories(outputBasketOfApplesStateParticipants) - .toSignedTransaction(); - assertFailsWith(transaction, "This transaction should have exactly one AppleStamp and one BasketOfApples input state"); - } - - @Test - public void appleStampIssuerDifferentFromBasketFarm() { - // The following test builds a transaction that would fail due to having the issuer not matching the farm. - // This is because the issuer of the apple stamp should be the farm that grew the apples. - AppleStamp appleStampStateDifferentIssuer = new AppleStamp( - outputAppleStampStateId, - outputAppleStampStateStampDesc, - aliceKey, - outputAppleStampStateHolder, - List.of(aliceKey, outputAppleStampStateHolder) - ); - StateAndRef invalidInputAppleStampState = createInputStateAppleStamp(appleStampStateDifferentIssuer); - StateAndRef inputBasketOfApplesStates = createInputStateBasketOfApples(outputBasketOfApplesState); - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addInputStates(List.of(invalidInputAppleStampState.getRef(), inputBasketOfApplesStates.getRef())) - .addOutputState(outputBasketOfApplesState) - .addCommand(new AppleCommands.Redeem()) - .addSignatories(outputBasketOfApplesStateParticipants) - .toSignedTransaction(); - assertFailsWith(transaction, "The issuer of the Apple stamp should be the producing farm of this basket of apple"); - } - - @Test - public void basketWeightIsZero() { - // The following test builds a transaction that would fail due to asking to redeem a basket without a valid weight. - BasketOfApples inputBasketOfApplesStatesZeroWeight = new BasketOfApples( - outputBasketOfApplesStateDescription, - outputBasketOfApplesStateFarm, - outputBasketOfApplesStateOwner, - 0, - outputBasketOfApplesStateParticipants - ); - StateAndRef inputAppleStampState = createInputStateAppleStamp(outputAppleStampState); - StateAndRef invalidInputBasketOfApplesStates = createInputStateBasketOfApples(inputBasketOfApplesStatesZeroWeight); - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addInputStates(List.of(inputAppleStampState.getRef(), invalidInputBasketOfApplesStates.getRef())) - .addOutputState(outputBasketOfApplesState) - .addCommand(new AppleCommands.Redeem()) - .addSignatories(outputBasketOfApplesStateParticipants) - .toSignedTransaction(); - assertFailsWith(transaction, "The basket of apple has to weigh more than 0"); - } - - /** - * Note how this test suite does not contain tests to check for missing or invalid commands. - * This is because The class to test for BasketOfApples state and AppleCommands.PackBasket command already included - * tests for the same contract, so implementing it again would be redundantly testing the contract - **/ -} \ No newline at end of file diff --git a/contracts/src/test/java/com/r3/developers/cordapptemplate/utxoexample/contracts/ChatContractCreateCommandTest.java b/contracts/src/test/java/com/r3/developers/cordapptemplate/utxoexample/contracts/ChatContractCreateCommandTest.java deleted file mode 100644 index b1a52dd..0000000 --- a/contracts/src/test/java/com/r3/developers/cordapptemplate/utxoexample/contracts/ChatContractCreateCommandTest.java +++ /dev/null @@ -1,196 +0,0 @@ -package com.r3.developers.cordapptemplate.utxoexample.contracts; - -import com.r3.corda.ledger.utxo.testing.ContractTest; -import com.r3.developers.cordapptemplate.utxoexample.states.ChatState; -import net.corda.v5.ledger.utxo.Command; -import net.corda.v5.ledger.utxo.StateAndRef; -import net.corda.v5.ledger.utxo.transaction.UtxoSignedTransaction; -import org.junit.jupiter.api.Test; - -import java.util.List; -import java.util.UUID; - -import static com.r3.developers.cordapptemplate.utxoexample.contracts.ChatContract.*; -import static java.util.Collections.emptyList; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * This class is an implementation of ContractTest. This provides functions to easily perform unit tests on contracts. - * This allows us to unit test our implementation of contracts without having to trigger a workflow. - **/ - -// This specific class is involved with testing the scenarios involving the ChatState state and the Create command. -public class ChatContractCreateCommandTest extends ContractTest { - - // The following are default values for states so that tests can easily refer and re-use them - protected ChatState outputChatState = new ChatState( - UUID.randomUUID(), - "aliceChatName", - aliceName, - "aliceChatMessage", - List.of(aliceKey, bobKey) - ); - - /** - * All Tests must start with the @Test annotation. Tests can be run individually by running them with your IDE. - * Alternatively, tests can be grouped up and tested by running the test from the line defining the class above. - * If you need help to write tests, think of a happy path scenario and then think of every line of code in the contract - * where the transaction could fail. - * It helps to meaningfully name tests so that you know exactly what success case or specific error you are testing for. - **/ - - @Test - public void happyPath() { - // The following test builds a transaction that should pass all the contract verification checks. - // The buildTransaction function helps create a utxoLedgerTransaction that can be referenced for contract tests - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState(outputChatState) - .addCommand(new ChatContract.Create()) - .addSignatories(outputChatState.participants) - .toSignedTransaction(); - /** - * The assertVerifies function is the general way to test if a contract test passes or fails a transaction. - * If the transaction is verified, then it means that the contract tests pass. - **/ - assertVerifies(transaction); - } - - @Test - public void missingCommand() { - // The following test builds a transaction that would fail due to not having a command. - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState(outputChatState) - .toSignedTransaction(); - assertFailsWith(transaction, "Failed requirement: " + REQUIRE_SINGLE_COMMAND); - } - - @Test - public void shouldNotAcceptUnknownCommand() { - // The following test builds a transaction that would fail due to providing an invalid command. - class MyDummyCommand implements Command { - } - - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState(outputChatState) - .addCommand(new MyDummyCommand()) - .addSignatories(outputChatState.participants) - .toSignedTransaction(); - - assertFailsWith(transaction, UNKNOWN_COMMAND); - } - - @Test - public void outputStateCannotHaveZeroParticipants() { - // The following test builds a transaction that would fail due to not providing participants, when the contract - // expects exactly two participants. - ChatState state = new ChatState( - UUID.randomUUID(), - "myChatName", - aliceName, - "myChatMessage", - emptyList() - ); - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState(state) - .addCommand(new ChatContract.Create()) - .toSignedTransaction(); - assertFailsWith(transaction, "Failed requirement: " + OUTPUT_STATE_SHOULD_ONLY_HAVE_TWO_PARTICIPANTS); - } - - @Test - public void outputStateCannotHaveOneParticipant() { - // The following test builds a transaction that would fail due to not providing the right number of participants. - // This test provides a list of only one participant, when the contract expects exactly two participants. - ChatState state = new ChatState( - UUID.randomUUID(), - "myChatName", - aliceName, - "myChatMessage", - List.of(aliceKey) - ); - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState(state) - .addCommand(new ChatContract.Create()) - .toSignedTransaction(); - assertFailsWith(transaction, "Failed requirement: " + OUTPUT_STATE_SHOULD_ONLY_HAVE_TWO_PARTICIPANTS); - } - - @Test - public void outputStateCannotHaveThreeParticipants() { - // The following test builds a transaction that would fail due to not providing the right number of participants. - // This test provides a list of three participants, when the contract expects exactly two participants. - ChatState state = new ChatState( - UUID.randomUUID(), - "myChatName", - aliceName, - "myChatMessage", - List.of(aliceKey, bobKey, charlieKey) - ); - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState(state) - .addCommand(new ChatContract.Create()) - .toSignedTransaction(); - assertFailsWith(transaction, "Failed requirement: " + OUTPUT_STATE_SHOULD_ONLY_HAVE_TWO_PARTICIPANTS); - } - - @Test - public void outputStateMustBeSigned() { - // The following test builds a transaction that would fail due to not signing the transaction. - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState(outputChatState) - .addCommand(new ChatContract.Create()) - .toSignedTransaction(); - assertFailsWith(transaction, "Failed requirement: " + TRANSACTION_SHOULD_BE_SIGNED_BY_ALL_PARTICIPANTS); - } - - @Test - public void outputStateCannotBeSignedByOnlyOneParticipant() { - // The following test builds a transaction that would fail due to being signed by only one participant and not - // all participants. - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState(outputChatState) - .addCommand(new ChatContract.Create()) - .addSignatories(outputChatState.participants.get(0)) - .toSignedTransaction(); - assertFailsWith(transaction, "Failed requirement: " + TRANSACTION_SHOULD_BE_SIGNED_BY_ALL_PARTICIPANTS); - } - - @Test - public void shouldNotIncludeInputState() { - // The following test builds a transaction that would fail due to providing an input state when the contract did - // not expect one - happyPath(); // generate an existing state to search for - StateAndRef existingState = getLedgerService().findUnconsumedStatesByType(ChatState.class).get(0); // doesn't matter which as this will fail validation - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addInputState(existingState.getRef()) - .addOutputState(outputChatState) - .addCommand(new ChatContract.Create()) - .addSignatories(outputChatState.participants) - .toSignedTransaction(); - assertFailsWith(transaction, "Failed requirement: " + CREATE_COMMAND_SHOULD_HAVE_NO_INPUT_STATES); - } - - @Test - public void shouldNotHaveTwoOutputStates() { - // The following test builds a transaction that would fail due to providing two output states when the contract - // only - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState(outputChatState) - .addOutputState(outputChatState) - .addCommand(new ChatContract.Create()) - .addSignatories(outputChatState.participants) - .toSignedTransaction(); - assertFailsWith(transaction, "Failed requirement: " + CREATE_COMMAND_SHOULD_HAVE_ONLY_ONE_OUTPUT_STATE); - } -} diff --git a/contracts/src/test/java/com/r3/developers/cordapptemplate/utxoexample/contracts/ChatContractUpdateCommandTest.java b/contracts/src/test/java/com/r3/developers/cordapptemplate/utxoexample/contracts/ChatContractUpdateCommandTest.java deleted file mode 100644 index 2a8b810..0000000 --- a/contracts/src/test/java/com/r3/developers/cordapptemplate/utxoexample/contracts/ChatContractUpdateCommandTest.java +++ /dev/null @@ -1,220 +0,0 @@ -package com.r3.developers.cordapptemplate.utxoexample.contracts; - -import com.r3.corda.ledger.utxo.testing.ContractTest; -import com.r3.developers.cordapptemplate.utxoexample.states.ChatState; -import net.corda.v5.ledger.utxo.StateAndRef; -import net.corda.v5.ledger.utxo.transaction.UtxoSignedTransaction; -import org.junit.jupiter.api.Test; - -import java.util.List; -import java.util.UUID; - -import static com.r3.developers.cordapptemplate.utxoexample.contracts.ChatContract.*; - -/** - * This class is an implementation of ContractTest. This provides functions to easily perform unit tests on contracts. - * This allows us to unit test our implementation of contracts without having to trigger a workflow. - **/ - -// This specific class is involved with testing the scenarios involving the ChatState state and the Update command. -public class ChatContractUpdateCommandTest extends ContractTest { - - // The following is a helper function to create a ChatState with default values. - // This is done so that we can easily re-use this block of code when writing our tests that require an input state - @SuppressWarnings("unchecked") - private StateAndRef createInitialChatState() { - ChatState outputChatState = new ChatContractCreateCommandTest().outputChatState; - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState(outputChatState) - .addCommand(new ChatContract.Create()) - .addSignatories(outputChatState.participants) - .toSignedTransaction(); - transaction.toLedgerTransaction(); - return (StateAndRef) transaction.getOutputStateAndRefs().get(0); - } - - /** - * All Tests must start with the @Test annotation. Tests can be run individually by running them with your IDE. - * Alternatively, tests can be grouped up and tested by running the test from the line defining the class above. - * If you need help to write tests, think of a happy path scenario and then think of every line of code in the contract - * where the transaction could fail. - * It helps to meaningfully name tests so that you know exactly what success case or specific error you are testing for. - **/ - - @Test - public void happyPath() { - // The following test builds a transaction that should pass all the contract verification checks. - // The buildTransaction function helps create a utxoLedgerTransaction that can be referenced for contract tests - StateAndRef existingState = createInitialChatState(); - ChatState updatedOutputChatState = existingState.getState().getContractState().updateMessage(bobName, "bobResponse"); - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addInputState(existingState.getRef()) - .addOutputState(updatedOutputChatState) - .addCommand(new ChatContract.Update()) - .addSignatories(updatedOutputChatState.participants) - .toSignedTransaction(); - /** - * The assertVerifies function is the general way to test if a contract test passes or fails a transaction. - * If the transaction is verified, then it means that the contract tests pass. - **/ - assertVerifies(transaction); - } - - @Test - public void shouldNotHaveNoInputState() { - // The following test builds a transaction that would fail due to not providing a input state, when the contract - // expects exactly one input state - StateAndRef existingState = createInitialChatState(); - ChatState updatedOutputChatState = existingState.getState().getContractState().updateMessage(bobName, "bobResponse"); - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addOutputState(updatedOutputChatState) - .addCommand(new ChatContract.Update()) - .addSignatories(updatedOutputChatState.participants) - .toSignedTransaction(); - /** - * The assertFailsWith function is the general way to test for unhappy path test cases contract tests. - * - * NOTE: the assertFailsWith method tests if the exact string of the error message matches the expected message - * to test if the string of the error message contains a substring within the error message, use the - * assertFailsWithMessageContaining() function using the same arguments. - **/ - assertFailsWith(transaction, "Failed requirement: " + UPDATE_COMMAND_SHOULD_HAVE_ONLY_ONE_INPUT_STATE); - } - - @Test - public void shouldNotHaveTwoInputStates() { - // The following test builds a transaction that would fail due to having two input states, when the contract - // expects exactly one. - StateAndRef existingState = createInitialChatState(); - ChatState updatedOutputChatState = existingState.getState().getContractState().updateMessage(bobName, "bobResponse"); - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addInputState(existingState.getRef()) - .addInputState(existingState.getRef()) - .addOutputState(updatedOutputChatState) - .addCommand(new ChatContract.Update()) - .addSignatories(updatedOutputChatState.participants) - .toSignedTransaction(); - assertFailsWith(transaction, "Failed requirement: " + UPDATE_COMMAND_SHOULD_HAVE_ONLY_ONE_INPUT_STATE); - } - - @Test - public void shouldNotHaveTwoOutputStates() { - // The following test builds a transaction that would fail due to having two output states, when the contract - // expects exactly one. - StateAndRef existingState = createInitialChatState(); - ChatState updatedOutputChatState = existingState.getState().getContractState().updateMessage(bobName, "bobResponse"); - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addInputState(existingState.getRef()) - .addOutputState(updatedOutputChatState) - .addOutputState(updatedOutputChatState) - .addCommand(new ChatContract.Update()) - .addSignatories(updatedOutputChatState.participants) - .toSignedTransaction(); - assertFailsWith(transaction, "Failed requirement: " + UPDATE_COMMAND_SHOULD_HAVE_ONLY_ONE_OUTPUT_STATE); - } - - @Test - public void idShouldNotChange() { - // The following test builds a transaction that would fail because the contract makes sure that the id of the - // output state does not change from the input state. - StateAndRef existingState = createInitialChatState(); - ChatState esDetails = existingState.getState().getContractState(); - ChatState updatedOutputChatState = new ChatState( - UUID.randomUUID(), - esDetails.getChatName(), - bobName, - "bobResponse", - esDetails.getParticipants() - ); - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addInputState(existingState.getRef()) - .addOutputState(updatedOutputChatState) - .addCommand(new ChatContract.Update()) - .addSignatories(updatedOutputChatState.participants) - .toSignedTransaction(); - assertFailsWith(transaction, "Failed requirement: " + UPDATE_COMMAND_ID_SHOULD_NOT_CHANGE); - } - - @Test - public void chatNameShouldNotChange() { - // The following test builds a transaction that would fail because the contract makes sure that the chatName of - // the output state does not change from the chat name from the input state. - StateAndRef existingState = createInitialChatState(); - ChatState esDetails = existingState.getState().getContractState(); - ChatState updatedOutputChatState = new ChatState( - esDetails.getId(), - "newName", - bobName, - "bobResponse", - esDetails.getParticipants() - ); - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addInputState(existingState.getRef()) - .addOutputState(updatedOutputChatState) - .addCommand(new ChatContract.Update()) - .addSignatories(updatedOutputChatState.participants) - .toSignedTransaction(); - assertFailsWith(transaction, "Failed requirement: " + UPDATE_COMMAND_CHATNAME_SHOULD_NOT_CHANGE); - } - - @Test - public void participantsShouldNotChange() { - // The following test builds a transaction that would fail because the contract makes sure that the list of - // participants from the output state does not change from the list of participants from the input state. - StateAndRef existingState = createInitialChatState(); - ChatState esDetails = existingState.getState().getContractState(); - ChatState updatedOutputChatState = new ChatState( - esDetails.getId(), - esDetails.getChatName(), - bobName, - "bobResponse", - List.of(bobKey, charlieKey) // The input state lists 'Alice' and 'Bob' as the participants - ); - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addInputState(existingState.getRef()) - .addOutputState(updatedOutputChatState) - .addCommand(new ChatContract.Update()) - .addSignatories(updatedOutputChatState.participants) - .toSignedTransaction(); - assertFailsWith(transaction, "Failed requirement: " + UPDATE_COMMAND_PARTICIPANTS_SHOULD_NOT_CHANGE); - } - - @Test - public void outputStateMustBeSigned() { - // The following test builds a transaction that would fail because it does not include signatories, where the - // contract expects all the participants to be signatories. - StateAndRef existingState = createInitialChatState(); - ChatState updatedOutputChatState = existingState.getState().getContractState().updateMessage(bobName, "bobResponse"); - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addInputState(existingState.getRef()) - .addOutputState(updatedOutputChatState) - .addCommand(new ChatContract.Update()) - .toSignedTransaction(); - assertFailsWith(transaction, "Failed requirement: " + TRANSACTION_SHOULD_BE_SIGNED_BY_ALL_PARTICIPANTS); - } - - @Test - public void outputStateCannotBeSignedByOnlyOneParticipant() { - // The following test builds a transaction that would fail because it only includes one signatory, where the - // contract expects all the participants to be signatories. - StateAndRef existingState = createInitialChatState(); - ChatState updatedOutputChatState = existingState.getState().getContractState().updateMessage(bobName, "bobResponse"); - UtxoSignedTransaction transaction = getLedgerService() - .createTransactionBuilder() - .addInputState(existingState.getRef()) - .addOutputState(updatedOutputChatState) - .addCommand(new ChatContract.Update()) - .addSignatories(updatedOutputChatState.participants.get(0)) - .toSignedTransaction(); - assertFailsWith(transaction, "Failed requirement: " + TRANSACTION_SHOULD_BE_SIGNED_BY_ALL_PARTICIPANTS); - } -} diff --git a/gradle.properties b/gradle.properties index 3259bf9..dc9c265 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,17 +2,17 @@ kotlin.code.style=official # Specify the version of the Corda-API to use. # This needs to match the version supported by the Corda Cluster the CorDapp will run on. -cordaApiVersion=5.2.0.49-RC02 +cordaApiVersion=5.2.0.52 # Specify the version of the notary plugins to use. # Currently packaged as part of corda-runtime-os, so should be set to a corda-runtime-os version. -cordaNotaryPluginsVersion=5.2.0.0-RC02 +cordaNotaryPluginsVersion=5.2.0.0 # Specify the version of the cordapp-cpb and cordapp-cpk plugins cordaPluginsVersion=7.0.4 # Specify the version of the Corda runtime Gradle plugin to use -cordaGradlePluginVersion=5.2.0.0-RC02 +cordaGradlePluginVersion=5.2.0.0 # Specify the name of the workflows module # This will be the name of the generated cpk and cpb files @@ -71,7 +71,3 @@ vnodeRegistrationTimeoutDefault=30000 # False by default, will execute the tests every time you stand the template up - gives extra protection # Set to true to skip the tests, making the launching process quicker. You will be responsible for running workflow tests yourself skipTestsDuringBuildCpis=false - -# R3 internal repository -# Use this version when pointing to artefacts in artifactory that have not been published to S3 -artifactoryContextUrl=https://software.r3.com/artifactory diff --git a/settings.gradle b/settings.gradle index 77a0eff..4676762 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,16 +4,6 @@ pluginManagement { gradlePluginPortal() mavenCentral() mavenLocal() - maven { - url = "$artifactoryContextUrl/corda-os-maven" - authentication { - basic(BasicAuthentication) - } - credentials { - username = settings.ext.find('cordaArtifactoryUsername') ?: System.getenv('CORDA_ARTIFACTORY_USERNAME') - password = settings.ext.find('cordaArtifactoryPassword') ?: System.getenv('CORDA_ARTIFACTORY_PASSWORD') - } - } } // The plugin dependencies with versions of the plugins congruent with the specified CorDapp plugin version,