ContractInterface { public ContractInvocationWithNothing newInvocationBuilder() { return new ContractInterface.InvocationBuilder(this); }  ContractFunction findFunction(final String functionName); ContractInvocationWithNothing newInvocationBuilder();  }
@Test public void testInvocationBuilder() { final ContractAddress address = new ContractAddress(encodedAddress); final String version = randomUUID().toString(); final String language = randomUUID().toString(); final ContractFunction function = new ContractFunction(functionName, Collections.<String>emptyList(), false, false, true); final List<ContractFunction> functions = asList(function); final List<StateVariable> stateVariables = new ArrayList<StateVariable>(); final ContractInterface contractInterface = ContractInterface.newBuilder() .address(address) .version(version) .language(language) .functions(functions) .stateVariables(stateVariables) .build(); final Object[] args = new Object[]{randomUUID().toString(), randomUUID().toString()}; final ContractInvocation expected = ContractInvocation .newBuilder() .address(address) .functionName(functionName) .args(asList(args)) .amount(Aer.EMPTY) .delegateFee(true) .build(); final ContractInvocation actual = contractInterface.newInvocationBuilder() .function(functionName) .args(args) .amount(Aer.EMPTY) .delegateFee(true) .build(); assertEquals(expected, actual); }
@Test public void testInvocationBuilderOnListArgs() { final ContractAddress address = new ContractAddress(encodedAddress); final String version = randomUUID().toString(); final String language = randomUUID().toString(); final ContractFunction function = new ContractFunction(functionName, Collections.<String>emptyList(), false, false, true); final List<ContractFunction> functions = asList(function); final List<StateVariable> stateVariables = new ArrayList<StateVariable>(); final ContractInterface contractInterface = ContractInterface.newBuilder() .address(address) .version(version) .language(language) .functions(functions) .stateVariables(stateVariables) .build(); final List<Object> args = Arrays.<Object>asList(randomUUID().toString(), randomUUID().toString()); final ContractInvocation expected = ContractInvocation .newBuilder() .address(address) .functionName(functionName) .args(args) .amount(Aer.EMPTY) .delegateFee(true) .build(); final ContractInvocation actual = contractInterface.newInvocationBuilder() .function(functionName) .args(args) .amount(Aer.EMPTY) .delegateFee(true) .build(); assertEquals(expected, actual); }
@Test public void testInvocationBuilderWithInvalidFunction() { final ContractAddress address = new ContractAddress(encodedAddress); final String version = randomUUID().toString(); final String language = randomUUID().toString(); final ContractFunction function = new ContractFunction(functionName); final List<ContractFunction> functions = new ArrayList<ContractFunction>(); functions.add(function); final List<StateVariable> stateVariables = new ArrayList<StateVariable>(); final ContractInterface contractInterface = ContractInterface.newBuilder() .address(address) .version(version) .language(language) .functions(functions) .stateVariables(stateVariables) .build(); final Object[] args = new Object[]{randomUUID().toString(), randomUUID().toString()}; try { contractInterface.newInvocationBuilder() .function(randomUUID().toString()) .args(args) .build(); fail(); } catch (Exception e) { } }
@Test public void testFeeDelegation() { final ContractAddress address = new ContractAddress(encodedAddress); final String version = randomUUID().toString(); final String language = randomUUID().toString(); final ContractFunction function = new ContractFunction(functionName, false, false, true); final List<ContractFunction> functions = new ArrayList<ContractFunction>(); functions.add(function); final List<StateVariable> stateVariables = new ArrayList<StateVariable>(); final ContractInterface contractInterface = ContractInterface.newBuilder() .address(address) .version(version) .language(language) .functions(functions) .stateVariables(stateVariables) .build(); final ContractInvocation invocation = contractInterface.newInvocationBuilder() .function(functionName) .amount(Aer.ZERO) .delegateFee(true) .build(); assertNotNull(invocation); }
@Test public void shouldThrowErrorOnNonFeeDelegateableFunction() { final ContractAddress address = new ContractAddress(encodedAddress); final String version = randomUUID().toString(); final String language = randomUUID().toString(); final ContractFunction function = new ContractFunction(functionName, false, false, false); final List<ContractFunction> functions = new ArrayList<ContractFunction>(); functions.add(function); final List<StateVariable> stateVariables = new ArrayList<StateVariable>(); final ContractInterface contractInterface = ContractInterface.newBuilder() .address(address) .version(version) .language(language) .functions(functions) .stateVariables(stateVariables) .build(); try { contractInterface.newInvocationBuilder() .function(functionName) .amount(Aer.ZERO) .delegateFee(true) .build(); fail(); } catch (Exception e) { } }
@Test public void shouldNotThrowErrorNotFeeDelegegatableOne() { final ContractAddress address = new ContractAddress(encodedAddress); final String version = randomUUID().toString(); final String language = randomUUID().toString(); final ContractFunction function = new ContractFunction(functionName, false, false, false); final List<ContractFunction> functions = new ArrayList<ContractFunction>(); functions.add(function); final List<StateVariable> stateVariables = new ArrayList<StateVariable>(); final ContractInterface contractInterface = ContractInterface.newBuilder() .address(address) .version(version) .language(language) .functions(functions) .stateVariables(stateVariables) .build(); final ContractInvocation invocation = contractInterface.newInvocationBuilder() .function(functionName) .amount(Aer.ZERO) .delegateFee(false) .build(); assertNotNull(invocation); }