Skip to content

Commit

Permalink
[FAB-13802] Return types update
Browse files Browse the repository at this point in the history
Change-Id: Ib4be076c2bc31a363485eb8080c4501a0fb106f2
Signed-off-by: Matthew B. White <[email protected]>
  • Loading branch information
mbwhite committed Apr 29, 2019
1 parent 8d34b20 commit 526f36d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static class ContextInvocationHandler implements InvocationHandler {

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Method m = stub.getClass().getMethod(method.getName(), method.getParameterTypes());
Method m = ChaincodeStub.class.getMethod(method.getName(), method.getParameterTypes());
return m.invoke(stub, args);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static java.nio.charset.StandardCharsets.UTF_8;

public class ContractExecutionService implements ExecutionService {

Expand All @@ -54,7 +55,13 @@ public Chaincode.Response executeRequest(Routing rd, InvocationRequest req, Chai

Chaincode.Response response;
try {
response = (Chaincode.Response)rd.getMethod().invoke(proxyObject, args.toArray());
Object value = rd.getMethod().invoke(proxyObject, args.toArray());
if (value==null){
response = ResponseUtils.newSuccessResponse();
} else {
String str = value.toString();
response = ResponseUtils.newSuccessResponse(str.getBytes(UTF_8));
}
} catch (IllegalAccessException|InvocationTargetException e) {
logger.warn("Error during contract method invocation", e);
response = ResponseUtils.newErrorResponse(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ public class SampleContract implements ContractInterface {
static public int i1Invoked = 0;

@Init
public Chaincode.Response i1() {
public String i1() {
i1Invoked++;
return ResponseUtils.newSuccessResponse("Init done");
return "Init done";
}

@Transaction
public Chaincode.Response t1(String arg1) {
public String t1(String arg1) {
t1Invoked++;
Context context = getContext();
List<String> args = context.getStringArgs();
doSomeWork();
return ResponseUtils.newSuccessResponse(args.get(1));
return args.get(1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;


import static java.nio.charset.StandardCharsets.UTF_8;
public class ContractRouterTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
Expand Down Expand Up @@ -81,7 +81,7 @@ public void testInit() {
SampleContract.i1Invoked = 0;
Chaincode.Response response = r.init(s);
assertThat(response, is(notNullValue()));
assertThat(response.getMessage(), is(equalTo("Init done")));
assertThat(response.getStringPayload(), is(equalTo("Init done")));
assertThat(SampleContract.beforeInvoked, is(1));
assertThat(SampleContract.afterInvoked, is(1));
assertThat(SampleContract.i1Invoked, is(1));
Expand Down Expand Up @@ -118,7 +118,7 @@ public void testInvoke() {

Chaincode.Response response = r.invoke(s);
assertThat(response, is(notNullValue()));
assertThat(response.getMessage(), is(equalTo("asdf")));
assertThat(response.getStringPayload(), is(equalTo("asdf")));
assertThat(SampleContract.beforeInvoked, is(1));
assertThat(SampleContract.afterInvoked, is(1));
assertThat(SampleContract.doWorkInvoked, is(1));
Expand Down

0 comments on commit 526f36d

Please sign in to comment.