use of org.fisco.bcos.web3j.abi.datatypes.Function in project web3sdk by FISCO-BCOS.
the class RevertResolverTest method isOutputStartWithRevertMethodTest.
@Test
public void isOutputStartWithRevertMethodTest() {
String revertMessage = "isOutputStartWithRevertMethodTest";
Function revertFunction = newFunction("Error", revertMessage);
String revertABI = FunctionEncoder.encode(revertFunction);
Function testFunction = newFunction("testFunc", revertMessage);
String testABI = FunctionEncoder.encode(testFunction);
assertTrue(RevertResolver.isOutputStartWithRevertMethod(revertABI));
assertFalse(RevertResolver.isOutputStartWithRevertMethod(testABI));
assertTrue(RevertResolver.isOutputStartWithRevertMethod(revertABI));
assertFalse(RevertResolver.isOutputStartWithRevertMethod(testABI));
}
use of org.fisco.bcos.web3j.abi.datatypes.Function in project web3sdk by FISCO-BCOS.
the class RevertResolverTest method tryResolveRevertMessageTest0.
@Test
public void tryResolveRevertMessageTest0() throws IOException {
String revertMessage = "";
Function revertFunction = newFunction("Error", revertMessage);
String revertABI = FunctionEncoder.encode(revertFunction);
Function testFunction = newFunction("testFunc", revertMessage);
String testABI = FunctionEncoder.encode(testFunction);
Tuple2<Boolean, String> booleanStringTuple2 = RevertResolver.tryResolveRevertMessage("", "");
assertFalse(booleanStringTuple2.getValue1());
Tuple2<Boolean, String> booleanStringTuple20 = RevertResolver.tryResolveRevertMessage("0x0", revertABI);
assertFalse(booleanStringTuple20.getValue1());
Tuple2<Boolean, String> booleanStringTuple21 = RevertResolver.tryResolveRevertMessage("0x0", testABI);
assertFalse(booleanStringTuple21.getValue1());
Tuple2<Boolean, String> booleanStringTuple22 = RevertResolver.tryResolveRevertMessage("0x1", testABI);
assertFalse(booleanStringTuple22.getValue1());
Tuple2<Boolean, String> booleanStringTuple23 = RevertResolver.tryResolveRevertMessage("0x1", revertABI);
assertTrue(booleanStringTuple23.getValue1());
assertEquals(booleanStringTuple23.getValue2(), revertMessage);
}
use of org.fisco.bcos.web3j.abi.datatypes.Function in project web3sdk by FISCO-BCOS.
the class RevertResolverTest method tryResolveRevertMessageSMTest0.
@Test
public void tryResolveRevertMessageSMTest0() throws IOException {
EncryptType.setEncryptType(EncryptType.SM2_TYPE);
String revertMessage = "";
Function revertFunction = newFunction("Error", revertMessage);
String revertABI = FunctionEncoder.encode(revertFunction);
Function testFunction = newFunction("testFunc", revertMessage);
String testABI = FunctionEncoder.encode(testFunction);
Tuple2<Boolean, String> booleanStringTuple2 = RevertResolver.tryResolveRevertMessage("", "");
assertFalse(booleanStringTuple2.getValue1());
Tuple2<Boolean, String> booleanStringTuple20 = RevertResolver.tryResolveRevertMessage("0x0", revertABI);
assertFalse(booleanStringTuple20.getValue1());
Tuple2<Boolean, String> booleanStringTuple21 = RevertResolver.tryResolveRevertMessage("0x0", testABI);
assertFalse(booleanStringTuple21.getValue1());
Tuple2<Boolean, String> booleanStringTuple22 = RevertResolver.tryResolveRevertMessage("0x1", testABI);
assertFalse(booleanStringTuple22.getValue1());
Tuple2<Boolean, String> booleanStringTuple23 = RevertResolver.tryResolveRevertMessage("0x1", revertABI);
assertTrue(booleanStringTuple23.getValue1());
assertEquals(booleanStringTuple23.getValue2(), revertMessage);
EncryptType.setEncryptType(EncryptType.ECDSA_TYPE);
}
use of org.fisco.bcos.web3j.abi.datatypes.Function in project web3sdk by FISCO-BCOS.
the class TransactionDecoder method decodeOutputReturnObject.
/**
* @param input
* @param output
* @return
* @throws BaseException
*/
public InputAndOutputResult decodeOutputReturnObject(String input, String output) throws BaseException {
String updatedInput = addHexPrefixToString(input);
String updatedOutput = addHexPrefixToString(output);
// select abi
AbiDefinition abiDefinition = selectAbiDefinition(updatedInput);
// decode output
List<NamedType> outputTypes = abiDefinition.getOutputs();
List<TypeReference<?>> outputTypeReference = ContractAbiUtil.paramFormat(outputTypes);
Function function = new Function(abiDefinition.getName(), null, outputTypeReference);
List<Type> resultType = FunctionReturnDecoder.decode(updatedOutput, function.getOutputParameters());
// set result to java bean
List<ResultEntity> resultList = new ArrayList<>();
for (int i = 0; i < outputTypes.size(); i++) {
resultList.add(new ResultEntity(outputTypes.get(i).getName(), outputTypes.get(i).getType(), resultType.get(i)));
}
String methodSign = decodeMethodSign(abiDefinition);
return new InputAndOutputResult(methodSign, FunctionEncoder.buildMethodId(methodSign), resultList);
}
use of org.fisco.bcos.web3j.abi.datatypes.Function in project web3sdk by FISCO-BCOS.
the class TransactionDecoder method decodeInputReturnObject.
/**
* @param input
* @return
* @throws BaseException
*/
public InputAndOutputResult decodeInputReturnObject(String input) throws BaseException {
String updatedInput = addHexPrefixToString(input);
// select abi
AbiDefinition abiDefinition = selectAbiDefinition(updatedInput);
// decode input
List<NamedType> inputTypes = abiDefinition.getInputs();
List<TypeReference<?>> inputTypeReferences = ContractAbiUtil.paramFormat(inputTypes);
Function function = new Function(abiDefinition.getName(), null, inputTypeReferences);
List<Type> resultType = FunctionReturnDecoder.decode(updatedInput.substring(10), function.getOutputParameters());
// set result to java bean
List<ResultEntity> resultList = new ArrayList<ResultEntity>();
for (int i = 0; i < inputTypes.size(); i++) {
resultList.add(new ResultEntity(inputTypes.get(i).getName(), inputTypes.get(i).getType(), resultType.get(i)));
}
String methodSign = decodeMethodSign(abiDefinition);
return new InputAndOutputResult(methodSign, FunctionEncoder.buildMethodId(methodSign), resultList);
}
Aggregations