Skip to content

Commit 5bc4069

Browse files
committed
Merge branch 'release/1.16.0'
2 parents 704d1fe + 0f3dc49 commit 5bc4069

File tree

10 files changed

+106
-12
lines changed

10 files changed

+106
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 1.16.0
2+
3+
## What's Changed
4+
* adding method to abi result object by @barnjamin in https://github.com/algorand/java-algorand-sdk/pull/334
5+
* adding tests and methods for getMethodByName by @barnjamin in https://github.com/algorand/java-algorand-sdk/pull/337
6+
17
# 1.15.0
28

39
## What's Changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
unit:
2-
mvn test -Dcucumber.filter.tags="@unit.offline or @unit.algod or @unit.indexer or @unit.rekey or @unit.indexer.rekey or @unit.transactions or @unit.transactions.keyreg or @unit.responses or @unit.applications or @unit.dryrun or @unit.tealsign or @unit.responses.messagepack or @unit.responses.231 or @unit.responses.messagepack.231 or @unit.feetest or @unit.indexer.logs or @unit.abijson or @unit.atomic_transaction_composer or @unit.transactions.payment or @unit.responses.unlimited_assets or @unit.algod.ledger_refactoring or @unit.indexer.ledger_refactoring or @unit.dryrun.trace.application"
2+
mvn test -Dcucumber.filter.tags="@unit.offline or @unit.algod or @unit.indexer or @unit.rekey or @unit.indexer.rekey or @unit.transactions or @unit.transactions.keyreg or @unit.responses or @unit.applications or @unit.dryrun or @unit.tealsign or @unit.responses.messagepack or @unit.responses.231 or @unit.responses.messagepack.231 or @unit.feetest or @unit.indexer.logs or @unit.abijson or @unit.abijson.byname or @unit.atomic_transaction_composer or @unit.transactions.payment or @unit.responses.unlimited_assets or @unit.algod.ledger_refactoring or @unit.indexer.ledger_refactoring or @unit.dryrun.trace.application"
33

44
integration:
55
mvn test -Dcucumber.filter.tags="@algod or @assets or @auction or @kmd or @send or @send.keyregtxn or @indexer or @rekey or @applications.verified or @applications or @compile or @dryrun or @indexer.applications or @indexer.231 or @abi or @c2c"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Maven:
1919
<dependency>
2020
<groupId>com.algorand</groupId>
2121
<artifactId>algosdk</artifactId>
22-
<version>1.15.0</version>
22+
<version>1.16.0</version>
2323
</dependency>
2424
```
2525

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.algorand</groupId>
66
<artifactId>algosdk</artifactId>
7-
<version>1.15.0</version>
7+
<version>1.16.0</version>
88
<packaging>jar</packaging>
99

1010
<name>${project.groupId}:${project.artifactId}</name>

src/main/java/com/algorand/algosdk/abi/Contract.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.algorand.algosdk.abi;
22

3+
import com.algorand.algosdk.algod.client.StringUtil;
34
import com.fasterxml.jackson.annotation.JsonCreator;
45
import com.fasterxml.jackson.annotation.JsonIgnore;
56
import com.fasterxml.jackson.annotation.JsonInclude;
@@ -55,6 +56,11 @@ public Method getMethodByIndex(int index) {
5556
return this.methods.get(index);
5657
}
5758

59+
@JsonIgnore
60+
public Method getMethodByName(String name) {
61+
return Method.getMethodByName(this.methods, name);
62+
}
63+
5864
@Override
5965
public boolean equals(Object o) {
6066
if (o == null || getClass() != o.getClass()) return false;

src/main/java/com/algorand/algosdk/abi/Interface.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.algorand.algosdk.abi;
22

3+
import com.algorand.algosdk.algod.client.StringUtil;
34
import com.fasterxml.jackson.annotation.JsonCreator;
45
import com.fasterxml.jackson.annotation.JsonIgnore;
56
import com.fasterxml.jackson.annotation.JsonInclude;
@@ -44,6 +45,11 @@ public Method getMethodByIndex(int index) {
4445
return this.methods.get(index);
4546
}
4647

48+
@JsonIgnore
49+
public Method getMethodByName(String name) {
50+
return Method.getMethodByName(this.methods, name);
51+
}
52+
4753
@Override
4854
public boolean equals(Object o) {
4955
if (o == null || getClass() != o.getClass()) return false;

src/main/java/com/algorand/algosdk/abi/Method.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,32 @@ public boolean equals(Object o) {
180180
Objects.equals(args, method.args) && Objects.equals(returns, method.returns);
181181
}
182182

183+
184+
@JsonIgnore
185+
public static Method getMethodByName(List<Method> methods, String name) {
186+
List<Method> filteredMethods = new ArrayList<>();
187+
for(Method m: methods){
188+
if(m.name.equals(name)){
189+
filteredMethods.add(m);
190+
}
191+
}
192+
193+
if(filteredMethods.size()>1){
194+
String[] sigs = new String[filteredMethods.size()];
195+
for(int idx=0;idx<filteredMethods.size();idx++){
196+
sigs[idx] = filteredMethods.get(idx).getSignature();
197+
}
198+
String found = StringUtil.join(sigs, ",");
199+
throw new IllegalArgumentException(String.format("found %d methods with the same name: %s", filteredMethods.size(), found));
200+
}
201+
202+
if(filteredMethods.size()==0){
203+
throw new IllegalArgumentException(String.format("found 0 methods with the name %s", name));
204+
}
205+
206+
return filteredMethods.get(0);
207+
}
208+
183209
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
184210
public static class Returns {
185211
@JsonIgnore

src/main/java/com/algorand/algosdk/transaction/AtomicTransactionComposer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ public ExecuteResult execute(AlgodClient client, int waitRounds) throws Exceptio
277277
signedTxns.get(i).transactionID,
278278
null,
279279
null,
280+
this.methodMap.get(i),
280281
new Exception(resp.message()),
281282
null
282283
));
@@ -290,6 +291,7 @@ public ExecuteResult execute(AlgodClient client, int waitRounds) throws Exceptio
290291
currentTxInfo.txn.transactionID,
291292
null,
292293
null,
294+
this.methodMap.get(i),
293295
null,
294296
currentTxInfo
295297
));
@@ -315,6 +317,7 @@ public ExecuteResult execute(AlgodClient client, int waitRounds) throws Exceptio
315317
currentTxInfo.txn.transactionID,
316318
abiEncoded,
317319
decoded,
320+
this.methodMap.get(i),
318321
parseError,
319322
currentTxInfo
320323
));
@@ -349,14 +352,16 @@ public static class ReturnValue {
349352
public String txID;
350353
public byte[] rawValue;
351354
public Object value;
355+
public Method method;
352356
public Exception parseError;
353357
public PendingTransactionResponse txInfo;
354358

355-
public ReturnValue(String txID, byte[] rawValue, Object value,
359+
public ReturnValue(String txID, byte[] rawValue, Object value, Method method,
356360
Exception parseError, PendingTransactionResponse txInfo) {
357361
this.txID = txID;
358362
this.rawValue = rawValue;
359363
this.value = value;
364+
this.method = method;
360365
this.parseError = parseError;
361366
this.txInfo = txInfo;
362367
}

src/test/java/com/algorand/algosdk/integration/AtomicTxnComposer.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public class AtomicTxnComposer {
4242
AtomicTransactionComposer.ExecuteResult execRes;
4343
SplitAndProcessMethodArgs abiArgProcessor;
4444
Long appID;
45-
List<Method> composerMethods;
4645
String nonce;
4746

4847
public AtomicTxnComposer(Stepdefs stepdefs, Applications apps, TransactionSteps steps) {
@@ -79,7 +78,6 @@ public void an_application_id(Integer int1) {
7978
@Given("a new AtomicTransactionComposer")
8079
public void a_new_atomic_transaction_composer() {
8180
this.atc = new AtomicTransactionComposer();
82-
composerMethods = new ArrayList<>();
8381
}
8482

8583
@When("I make a transaction signer for the transient account.")
@@ -139,11 +137,10 @@ public void i_execute_the_current_transaction_group_with_the_composer() throws E
139137
public void the_app_should_have_returned(String string) {
140138
String[] splitEncoding = string.split(",");
141139
assertThat(execRes.methodResults.size()).isEqualTo(splitEncoding.length);
142-
assertThat(execRes.methodResults.size()).isEqualTo(composerMethods.size());
143140

144141
for (int i = 0; i < splitEncoding.length; i++) {
145142
AtomicTransactionComposer.ReturnValue execRetVal = execRes.methodResults.get(i);
146-
Method currMethod = composerMethods.get(i);
143+
Method currMethod = execRetVal.method;
147144
assertThat(execRetVal.parseError).isNull();
148145

149146
if (splitEncoding[i].isEmpty()) {
@@ -324,7 +321,6 @@ public void the_composer_should_have_a_status_of(String string) {
324321
@When("I add a method call with the transient account, the current application, suggested params, on complete {string}, current transaction signer, current method arguments.")
325322
public void i_add_a_method_call_with_the_signing_account_the_current_application_suggested_params_on_complete_current_transaction_signer_current_method_arguments(String onComplete) {
326323
Address senderAddress = applications.transientAccount.transientAccount.getAddress();
327-
composerMethods.add(method);
328324

329325
optionBuilder
330326
.onComplete(Transaction.OnCompletion.String(onComplete))
@@ -345,7 +341,6 @@ public void i_add_a_method_call_with_the_signing_account_the_current_application
345341
@When("I add a nonced method call with the transient account, the current application, suggested params, on complete {string}, current transaction signer, current method arguments.")
346342
public void i_add_a_nonced_method_call_with_the_transient_account_the_current_application_suggested_params_on_complete_current_transaction_signer_current_method_arguments(String onComplete) {
347343
Address senderAddress = applications.transientAccount.transientAccount.getAddress();
348-
composerMethods.add(method);
349344

350345
optionBuilder
351346
.onComplete(Transaction.OnCompletion.String(onComplete))
@@ -373,7 +368,6 @@ public void i_add_a_method_call_with_the_transient_account_the_current_applicati
373368
} catch (Exception e) {
374369
throw new IllegalArgumentException("cannot read resource from specified TEAL files");
375370
}
376-
composerMethods.add(method);
377371

378372
Address senderAddress = applications.transientAccount.transientAccount.getAddress();
379373

@@ -410,7 +404,6 @@ public void i_add_a_method_call_with_the_transient_account_the_current_applicati
410404
} catch (Exception e) {
411405
throw new IllegalArgumentException("cannot read resource from specified TEAL files");
412406
}
413-
composerMethods.add(method);
414407

415408
Address senderAddress = applications.transientAccount.transientAccount.getAddress();
416409

src/test/java/com/algorand/algosdk/unit/ABIJson.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Arrays;
2020
import java.util.Collections;
2121
import java.util.HashMap;
22+
import java.util.List;
2223

2324
public class ABIJson {
2425
private enum CHECK_FIELD {
@@ -35,6 +36,9 @@ private enum CHECK_FIELD {
3536
String jsonContract = null;
3637
CHECK_FIELD state = null;
3738

39+
List<Method> methods = null;
40+
String errString = null;
41+
3842
@When("I create the Method object from method signature {string}")
3943
public void i_create_the_method_object_from_method_signature(String string) {
4044
this.method = new Method(string);
@@ -149,4 +153,52 @@ public void the_deserialized_json_should_equal_the_original_contract_object() th
149153
Contract deserialized = new ObjectMapper().readValue(this.jsonContract, Contract.class);
150154
assertThat(this.contract).isEqualTo(deserialized);
151155
}
156+
157+
@When("I append to my Method objects list in the case of a non-empty signature {string}")
158+
public void i_append_to_my_method_objects_list_in_the_case_of_a_non_empty_signature(String methodsig) {
159+
if(this.methods == null){
160+
this.methods = new ArrayList<>();
161+
}
162+
163+
if(!methodsig.isEmpty()){
164+
this.methods.add(new Method(methodsig));
165+
}
166+
}
167+
168+
@When("I create an Interface object from my Method objects list")
169+
public void i_create_an_interface_object_from_my_method_objects_list() {
170+
this.interfaceObj = new Interface("", "", this.methods);
171+
}
172+
@When("I get the method from the Interface by name {string}")
173+
public void i_get_the_method_from_the_interface_by_name(String name) {
174+
try {
175+
this.method = this.interfaceObj.getMethodByName(name);
176+
}catch(Exception e){
177+
this.errString = e.getMessage();
178+
}
179+
}
180+
181+
@When("I create a Contract object from my Method objects list")
182+
public void i_create_a_contract_object_from_my_method_objects_list() {
183+
this.contract = new Contract("", "", null, this.methods);
184+
}
185+
186+
@When("I get the method from the Contract by name {string}")
187+
public void i_get_the_method_from_the_contract_by_name(String name) {
188+
try {
189+
this.method = this.contract.getMethodByName(name);
190+
}catch(Exception e){
191+
this.errString = e.getMessage();
192+
}
193+
}
194+
195+
@Then("the produced method signature should equal {string}. If there is an error it begins with {string}")
196+
public void the_produced_method_signature_should_equal_if_there_is_an_error_it_begins_with(String sig, String errstr) {
197+
if(!errstr.isEmpty()){
198+
assertThat(this.errString).startsWith(errstr);
199+
}else{
200+
assertThat(this.method.getSignature()).isEqualTo(sig);
201+
}
202+
}
203+
152204
}

0 commit comments

Comments
 (0)