Search in sources :

Example 1 with InstallProposalBuilder

use of org.hyperledger.fabric.sdk.transaction.InstallProposalBuilder in project fabric-sdk-java by hyperledger.

the class ChannelTest method testProposalBuilderWithOutMetaInf.

@Test
public void testProposalBuilderWithOutMetaInf() throws Exception {
    InstallProposalBuilder installProposalBuilder = InstallProposalBuilder.newBuilder();
    installProposalBuilder.setChaincodeLanguage(TransactionRequest.Type.GO_LANG);
    installProposalBuilder.chaincodePath("github.com/example_cc");
    installProposalBuilder.setChaincodeSource(new File(SAMPLE_GO_CC));
    installProposalBuilder.chaincodeName("example_cc.go");
    installProposalBuilder.chaincodeVersion("1");
    Channel channel = hfclient.newChannel("testProposalBuilderWithOutMetaInf");
    TransactionContext transactionContext = new TransactionContext(channel, getMockUser("rick", "rickORG"), CryptoSuite.Factory.getCryptoSuite());
    installProposalBuilder.context(transactionContext);
    // Build it get the proposal. Then unpack it to see if it's what we expect.
    FabricProposal.Proposal proposal = installProposalBuilder.build();
    FabricProposal.ChaincodeProposalPayload chaincodeProposalPayload = FabricProposal.ChaincodeProposalPayload.parseFrom(proposal.getPayload());
    Chaincode.ChaincodeInvocationSpec chaincodeInvocationSpec = Chaincode.ChaincodeInvocationSpec.parseFrom(chaincodeProposalPayload.getInput());
    Chaincode.ChaincodeSpec chaincodeSpec = chaincodeInvocationSpec.getChaincodeSpec();
    Chaincode.ChaincodeInput input = chaincodeSpec.getInput();
    Chaincode.ChaincodeDeploymentSpec chaincodeDeploymentSpec = Chaincode.ChaincodeDeploymentSpec.parseFrom(input.getArgs(1));
    ByteString codePackage = chaincodeDeploymentSpec.getCodePackage();
    ArrayList tarBytesToEntryArrayList = tarBytesToEntryArrayList(codePackage.toByteArray());
    ArrayList<String> expect = new ArrayList(Arrays.asList(new String[] { "src/github.com/example_cc/example_cc.go" }));
    assertArrayListEquals("Tar in Install Proposal's codePackage does not have expected entries. ", expect, tarBytesToEntryArrayList);
}
Also used : InstallProposalBuilder(org.hyperledger.fabric.sdk.transaction.InstallProposalBuilder) ByteString(com.google.protobuf.ByteString) Chaincode(org.hyperledger.fabric.protos.peer.Chaincode) ArrayList(java.util.ArrayList) TestUtils.tarBytesToEntryArrayList(org.hyperledger.fabric.sdk.testutils.TestUtils.tarBytesToEntryArrayList) ByteString(com.google.protobuf.ByteString) FabricProposal(org.hyperledger.fabric.protos.peer.FabricProposal) TransactionContext(org.hyperledger.fabric.sdk.transaction.TransactionContext) File(java.io.File) Test(org.junit.Test)

Example 2 with InstallProposalBuilder

use of org.hyperledger.fabric.sdk.transaction.InstallProposalBuilder in project fabric-sdk-java by hyperledger.

the class ChannelTest method testProposalBuilderWithMetaInf.

@Test
public void testProposalBuilderWithMetaInf() throws Exception {
    InstallProposalBuilder installProposalBuilder = InstallProposalBuilder.newBuilder();
    installProposalBuilder.setChaincodeLanguage(TransactionRequest.Type.GO_LANG);
    installProposalBuilder.chaincodePath("github.com/example_cc");
    installProposalBuilder.setChaincodeSource(new File(SAMPLE_GO_CC));
    installProposalBuilder.chaincodeName("example_cc.go");
    installProposalBuilder.setChaincodeMetaInfLocation(new File("src/test/fixture/meta-infs/test1"));
    installProposalBuilder.chaincodeVersion("1");
    Channel channel = hfclient.newChannel("testProposalBuilderWithMetaInf");
    TestUtils.MockUser mockUser = getMockUser("rick", "rickORG");
    TransactionContext transactionContext = new TransactionContext(channel, mockUser, CryptoSuite.Factory.getCryptoSuite());
    installProposalBuilder.context(transactionContext);
    // Build it get the proposal. Then unpack it to see if it's what we expect.
    FabricProposal.Proposal proposal = installProposalBuilder.build();
    FabricProposal.ChaincodeProposalPayload chaincodeProposalPayload = FabricProposal.ChaincodeProposalPayload.parseFrom(proposal.getPayload());
    Chaincode.ChaincodeInvocationSpec chaincodeInvocationSpec = Chaincode.ChaincodeInvocationSpec.parseFrom(chaincodeProposalPayload.getInput());
    Chaincode.ChaincodeSpec chaincodeSpec = chaincodeInvocationSpec.getChaincodeSpec();
    Chaincode.ChaincodeInput input = chaincodeSpec.getInput();
    Chaincode.ChaincodeDeploymentSpec chaincodeDeploymentSpec = Chaincode.ChaincodeDeploymentSpec.parseFrom(input.getArgs(1));
    ByteString codePackage = chaincodeDeploymentSpec.getCodePackage();
    ArrayList tarBytesToEntryArrayList = tarBytesToEntryArrayList(codePackage.toByteArray());
    ArrayList<String> expect = new ArrayList(Arrays.asList(new String[] { "META-INF/statedb/couchdb/indexes/MockFakeIndex.json", "src/github.com/example_cc/example_cc.go" }));
    assertArrayListEquals("Tar in Install Proposal's codePackage does not have expected entries. ", expect, tarBytesToEntryArrayList);
}
Also used : InstallProposalBuilder(org.hyperledger.fabric.sdk.transaction.InstallProposalBuilder) ByteString(com.google.protobuf.ByteString) Chaincode(org.hyperledger.fabric.protos.peer.Chaincode) ArrayList(java.util.ArrayList) TestUtils.tarBytesToEntryArrayList(org.hyperledger.fabric.sdk.testutils.TestUtils.tarBytesToEntryArrayList) ByteString(com.google.protobuf.ByteString) TestUtils(org.hyperledger.fabric.sdk.testutils.TestUtils) FabricProposal(org.hyperledger.fabric.protos.peer.FabricProposal) TransactionContext(org.hyperledger.fabric.sdk.transaction.TransactionContext) File(java.io.File) Test(org.junit.Test)

Example 3 with InstallProposalBuilder

use of org.hyperledger.fabric.sdk.transaction.InstallProposalBuilder in project fabric-sdk-java by hyperledger.

the class ChannelTest method testProposalBuilderWithMetaInfEmpty.

@Test
public void testProposalBuilderWithMetaInfEmpty() throws Exception {
    thrown.expect(java.lang.IllegalArgumentException.class);
    thrown.expectMessage(matchesRegex("The META-INF directory.*src.test.fixture.meta-infs.emptyMetaInf.META-INF is empty\\."));
    // make it cause git won't check in empty directory
    File emptyINF = new File("src/test/fixture/meta-infs/emptyMetaInf/META-INF");
    if (!emptyINF.exists()) {
        emptyINF.mkdirs();
        emptyINF.deleteOnExit();
    }
    InstallProposalBuilder installProposalBuilder = InstallProposalBuilder.newBuilder();
    installProposalBuilder.setChaincodeLanguage(TransactionRequest.Type.GO_LANG);
    installProposalBuilder.chaincodePath("github.com/example_cc");
    installProposalBuilder.setChaincodeSource(new File(SAMPLE_GO_CC));
    installProposalBuilder.chaincodeName("example_cc.go");
    installProposalBuilder.chaincodeVersion("1");
    // points into which is not what's expected.
    installProposalBuilder.setChaincodeMetaInfLocation(new File("src/test/fixture/meta-infs/emptyMetaInf"));
    Channel channel = hfclient.newChannel("testProposalBuilderWithMetaInfEmpty");
    TransactionContext transactionContext = new TransactionContext(channel, getMockUser("rick", "rickORG"), CryptoSuite.Factory.getCryptoSuite());
    installProposalBuilder.context(transactionContext);
    // Build it get the proposal. Then unpack it to see if it's what we epect.
    FabricProposal.Proposal proposal = installProposalBuilder.build();
}
Also used : FabricProposal(org.hyperledger.fabric.protos.peer.FabricProposal) InstallProposalBuilder(org.hyperledger.fabric.sdk.transaction.InstallProposalBuilder) TransactionContext(org.hyperledger.fabric.sdk.transaction.TransactionContext) File(java.io.File) Test(org.junit.Test)

Example 4 with InstallProposalBuilder

use of org.hyperledger.fabric.sdk.transaction.InstallProposalBuilder in project fabric-sdk-java by hyperledger.

the class ChannelTest method testProposalBuilderWithMetaInfExistsNOT.

@Test
public void testProposalBuilderWithMetaInfExistsNOT() throws Exception {
    thrown.expect(java.lang.IllegalArgumentException.class);
    thrown.expectMessage(matchesRegex("Directory to find chaincode META-INF.*tmp.fdsjfksfj.fjksfjskd.fjskfjdsk.should never exist does not exist"));
    InstallProposalBuilder installProposalBuilder = InstallProposalBuilder.newBuilder();
    installProposalBuilder.setChaincodeLanguage(TransactionRequest.Type.GO_LANG);
    installProposalBuilder.chaincodePath("github.com/example_cc");
    installProposalBuilder.setChaincodeSource(new File(SAMPLE_GO_CC));
    installProposalBuilder.chaincodeName("example_cc.go");
    installProposalBuilder.chaincodeVersion("1");
    // points into which is not what's expected.
    installProposalBuilder.setChaincodeMetaInfLocation(new File("/tmp/fdsjfksfj/fjksfjskd/fjskfjdsk/should never exist"));
    Channel channel = hfclient.newChannel("testProposalBuilderWithMetaInfExistsNOT");
    TransactionContext transactionContext = new TransactionContext(channel, getMockUser("rick", "rickORG"), CryptoSuite.Factory.getCryptoSuite());
    installProposalBuilder.context(transactionContext);
    // Build it get the proposal. Then unpack it to see if it's what we epect.
    installProposalBuilder.build();
}
Also used : InstallProposalBuilder(org.hyperledger.fabric.sdk.transaction.InstallProposalBuilder) TransactionContext(org.hyperledger.fabric.sdk.transaction.TransactionContext) File(java.io.File) Test(org.junit.Test)

Example 5 with InstallProposalBuilder

use of org.hyperledger.fabric.sdk.transaction.InstallProposalBuilder in project fabric-sdk-java by hyperledger.

the class ChannelTest method testProposalBuilderWithNoMetaInfDir.

@Test
public void testProposalBuilderWithNoMetaInfDir() throws Exception {
    thrown.expect(java.lang.IllegalArgumentException.class);
    thrown.expectMessage(matchesRegex("The META-INF directory does not exist in.*src.test.fixture.meta-infs.test1.META-INF"));
    InstallProposalBuilder installProposalBuilder = InstallProposalBuilder.newBuilder();
    installProposalBuilder.setChaincodeLanguage(TransactionRequest.Type.GO_LANG);
    installProposalBuilder.chaincodePath("github.com/example_cc");
    installProposalBuilder.setChaincodeSource(new File(SAMPLE_GO_CC));
    installProposalBuilder.chaincodeName("example_cc.go");
    installProposalBuilder.chaincodeVersion("1");
    // points into which is not what's expected.
    installProposalBuilder.setChaincodeMetaInfLocation(new File("src/test/fixture/meta-infs/test1/META-INF"));
    Channel channel = hfclient.newChannel("testProposalBuilderWithNoMetaInfDir");
    TransactionContext transactionContext = new TransactionContext(channel, getMockUser("rick", "rickORG"), CryptoSuite.Factory.getCryptoSuite());
    installProposalBuilder.context(transactionContext);
    // Build it get the proposal. Then unpack it to see if it's what we epect.
    installProposalBuilder.build();
}
Also used : InstallProposalBuilder(org.hyperledger.fabric.sdk.transaction.InstallProposalBuilder) TransactionContext(org.hyperledger.fabric.sdk.transaction.TransactionContext) File(java.io.File) Test(org.junit.Test)

Aggregations

InstallProposalBuilder (org.hyperledger.fabric.sdk.transaction.InstallProposalBuilder)6 TransactionContext (org.hyperledger.fabric.sdk.transaction.TransactionContext)6 File (java.io.File)5 Test (org.junit.Test)5 FabricProposal (org.hyperledger.fabric.protos.peer.FabricProposal)4 ByteString (com.google.protobuf.ByteString)2 ArrayList (java.util.ArrayList)2 Chaincode (org.hyperledger.fabric.protos.peer.Chaincode)2 TestUtils.tarBytesToEntryArrayList (org.hyperledger.fabric.sdk.testutils.TestUtils.tarBytesToEntryArrayList)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 SignedProposal (org.hyperledger.fabric.protos.peer.FabricProposal.SignedProposal)1 CryptoException (org.hyperledger.fabric.sdk.exception.CryptoException)1 EventHubException (org.hyperledger.fabric.sdk.exception.EventHubException)1 InvalidArgumentException (org.hyperledger.fabric.sdk.exception.InvalidArgumentException)1 ProposalException (org.hyperledger.fabric.sdk.exception.ProposalException)1 TransactionEventException (org.hyperledger.fabric.sdk.exception.TransactionEventException)1