Skip to content

Commit ceaa5fb

Browse files
committed
Merge branch 'release/1.18.0'
2 parents b9fa576 + 769affe commit ceaa5fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1279
-1660
lines changed

.test-env

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Configs for testing repo download:
2+
SDK_TESTING_URL="https://github.com/algorand/algorand-sdk-testing"
3+
SDK_TESTING_BRANCH="master"
4+
SDK_TESTING_HARNESS="test-harness"
5+
6+
VERBOSE_HARNESS=0
7+
8+
# WARNING: If set to 1, new features will be LOST when downloading the test harness.
9+
# REGARDLESS: modified features are ALWAYS overwritten.
10+
REMOVE_LOCAL_FEATURES=0
11+
12+
# WARNING: Be careful when turning on the next variable.
13+
# In that case you'll need to provide all variables expected by `algorand-sdk-testing`'s `.env`
14+
OVERWRITE_TESTING_ENVIRONMENT=0

CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
# 1.18.0
2+
3+
## What's Changed
4+
### Bugfixes
5+
* Bug-Fix: Pass verbosity to the harness and sandbox by @tzaffi in https://github.com/algorand/java-algorand-sdk/pull/371
6+
### New Features
7+
* StateProofs: Add State Proof support. by @winder in https://github.com/algorand/java-algorand-sdk/pull/360
8+
### Enhancements
9+
* Enhancement: Use Sandbox for Testing by @tzaffi in https://github.com/algorand/java-algorand-sdk/pull/363
10+
* Enhancement: Deprecating use of langspec by @ahangsu in https://github.com/algorand/java-algorand-sdk/pull/367
11+
12+
## New Contributors
13+
* @tzaffi made their first contribution in https://github.com/algorand/java-algorand-sdk/pull/363
14+
15+
**Full Changelog**: https://github.com/algorand/java-algorand-sdk/compare/1.17.0...1.18.0
16+
17+
# 1.18.0-beta-1
18+
## What's Changed
19+
### Bugfixes
20+
* Bug-Fix: Pass verbosity to the harness and sandbox by @tzaffi in https://github.com/algorand/java-algorand-sdk/pull/371
21+
### New Features
22+
* StateProofs: Add State Proof support. by @winder in https://github.com/algorand/java-algorand-sdk/pull/360
23+
### Enhancements
24+
* Enhancement: Use Sandbox for Testing by @tzaffi in https://github.com/algorand/java-algorand-sdk/pull/363
25+
* Enhancement: Deprecating use of langspec by @ahangsu in https://github.com/algorand/java-algorand-sdk/pull/367
26+
27+
## New Contributors
28+
* @tzaffi made their first contribution in https://github.com/algorand/java-algorand-sdk/pull/363
29+
30+
**Full Changelog**: https://github.com/algorand/java-algorand-sdk/compare/1.17.0...1.18.0-beta-1
31+
132
# 1.17.0
233
### New Features
334
* DevTools: adding source map decoder by @barnjamin in https://github.com/algorand/java-algorand-sdk/pull/352

Makefile

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1+
UNIT_TAGS := "$(subst :, or ,$(shell awk '{print $2}' src/test/unit.tags | paste -s -d: -))"
2+
INTEGRATION_TAGS := "$(subst :, or ,$(shell awk '{print $2}' src/test/integration.tags | paste -s -d: -))"
3+
14
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.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 or @unit.sourcemap"
5+
mvn test -Dcucumber.filter.tags=$(UNIT_TAGS)
36

47
integration:
5-
mvn test \
6-
-Dtest=com.algorand.algosdk.integration.RunCucumberIntegrationTest \
7-
-Dcucumber.filter.tags="@algod or @assets or @auction or @kmd or @send or @send.keyregtxn or @indexer or @rekey_v1 or @applications.verified or @applications or @compile or @dryrun or @indexer.applications or @indexer.231 or @abi or @c2c or @compile.sourcemap"
8+
mvn test -Dtest=com.algorand.algosdk.integration.RunCucumberIntegrationTest -Dcucumber.filter.tags=$(INTEGRATION_TAGS)
9+
10+
display-all-java-steps:
11+
find src/test/java/com/algorand/algosdk -name "*.java" | xargs grep "io.cucumber.java.en" 2>/dev/null | grep -v Binary | cut -d: -f1 | sort | uniq | xargs grep -E "@(Given|Then|When)"
12+
13+
harness:
14+
./test-harness.sh
15+
16+
docker-javasdk-build:
17+
# Build SDK testing environment
18+
docker build -t java-sdk-testing .
19+
20+
docker-javasdk-run:
21+
# Launch SDK testing
22+
docker run -it --network host java-sdk-testing:latest
823

9-
docker-test:
10-
./run_integration_tests.sh
24+
docker-test: harness docker-javasdk-build docker-javasdk-run

README.md

Lines changed: 17 additions & 2 deletions
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.17.0</version>
22+
<version>1.18.0</version>
2323
</dependency>
2424
```
2525

@@ -219,6 +219,13 @@ There is also a special integration test environment, and shared tests. To run t
219219
~$ make docker-test
220220
```
221221

222+
To stand up the test harness, without running the entire test suite use the Makefile:
223+
```
224+
~$ make harness
225+
```
226+
You can then run specific cucumber-based unit and integration tests directly.
227+
228+
222229
## deploying artifacts
223230

224231
The generated pom file provides maven compatibility and deploy capabilities.
@@ -229,6 +236,14 @@ mvn clean site -P github,default # for javadoc
229236
mvn clean deploy -P release,default
230237
```
231238

239+
# Testing
240+
241+
Many cross-SDK tests are defined in [algorand-sdk-testing](https://github.com/algorand/algorand-sdk-testing/). Some are integration tests with additional dependencies. These dependencies are containerized in a docker file, which can be executed with `make docker-test`.
242+
243+
It is occasionally useful to run locally, or against alternate integration branches. To do this:
244+
1. Install feature files for your test branch "./run_integration_tests.sh -feature-only -test-branch <branch here>"
245+
2. Run locally with `make integration` and `make unit`, or from the IDE by running "RunCucumberUnitTest.java"
246+
232247
# Android Support
233248

234249
Significant work has been taken to ensure Android compatibility (in particular for `minSdkVersion` 16). Note that the
@@ -245,7 +260,7 @@ A testing framework can also be generated with: `com.algorand.sdkutils.RunQueryM
245260

246261
## Regenerate the Client Code
247262

248-
To actually regenerate the code, use `run_generator.sh` with paths to the `*.oas2.json` files mentioned above.
263+
The actual generation is done using the `generate_java.sh` script in the [generator](https://github.com/algorand/generator/) repo.
249264

250265
# Updating the `kmd` REST client
251266
The `kmd` REST client has not been upgraded to use the new code generation, it is still largely autogenerated by `swagger-codegen`. [https://github.com/swagger-api/swagger-codegen]

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.17.0</version>
7+
<version>1.18.0</version>
88
<packaging>jar</packaging>
99

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

run_integration_tests.sh

Lines changed: 0 additions & 82 deletions
This file was deleted.

src/main/java/com/algorand/algosdk/crypto/LogicsigSignature.java

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.fasterxml.jackson.annotation.JsonInclude;
1717
import com.fasterxml.jackson.annotation.JsonProperty;
1818
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
19+
import org.apache.commons.codec.binary.Base64;
1920

2021
/**
2122
* Serializable logicsig class.
@@ -39,6 +40,59 @@ public class LogicsigSignature {
3940
@JsonProperty("msig")
4041
public MultisigSignature msig;
4142

43+
44+
private static boolean isAsciiPrintable(final byte symbol) {
45+
// linebreak existence check in program byte
46+
boolean isBreakLine = symbol == '\n';
47+
// printable ascii between range 32 (space) and 126 (tilde ~)
48+
boolean isStdPrintable = symbol >= ' ' && symbol <= '~';
49+
return isBreakLine || isStdPrintable;
50+
}
51+
52+
private static boolean isAsciiPrintable(final byte[] program) {
53+
for (byte b : program) {
54+
if (!isAsciiPrintable(b))
55+
return false;
56+
}
57+
return true;
58+
}
59+
60+
/**
61+
* Performs heuristic program validation:
62+
* check if passed in bytes are Algorand address or is B64 encoded, rather than Teal bytes
63+
* @param program
64+
*/
65+
private static void sanityCheckProgram(final byte[] program) {
66+
if (program == null || program.length == 0)
67+
throw new IllegalArgumentException("empty program");
68+
// in any case, if a slice of "program-bytes" is full of ASCII printable,
69+
// then the slice of bytes can't be Teal program bytes.
70+
// need to check what possible kind of bytes are passed in.
71+
if (isAsciiPrintable(program)) {
72+
// maybe the bytes passed in are representing an Algorand address
73+
boolean isAddress = false;
74+
try {
75+
new Address(new String(program));
76+
isAddress = true;
77+
} catch (NoSuchAlgorithmException | IllegalArgumentException e) {
78+
// if exception is IllegalArgException, it means bytes are not Algorand address
79+
if (e instanceof NoSuchAlgorithmException)
80+
throw new IllegalArgumentException("cannot check if program bytes are Algorand address" + e);
81+
}
82+
if (isAddress)
83+
throw new IllegalArgumentException("requesting program bytes, get Algorand address");
84+
85+
// or maybe these bytes are some B64 encoded bytes representation
86+
if (Base64.isBase64(program))
87+
throw new IllegalArgumentException("program should not be b64 encoded");
88+
89+
// can't further analyze, but it is more than just B64 encoding at this point
90+
throw new IllegalArgumentException(
91+
"program bytes are all ASCII printable characters, not looking like Teal byte code"
92+
);
93+
}
94+
}
95+
4296
@JsonCreator
4397
public LogicsigSignature(
4498
@JsonProperty("l") byte[] logic,
@@ -48,14 +102,8 @@ public LogicsigSignature(
48102
) {
49103
this.logic = Objects.requireNonNull(logic, "program must not be null");
50104
this.args = args;
51-
boolean verified = false;
52-
try {
53-
verified = Logic.checkProgram(this.logic, this.args);
54-
} catch (IOException ex) {
55-
throw new IllegalArgumentException("invalid program", ex);
56-
}
57105

58-
assert verified;
106+
sanityCheckProgram(this.logic);
59107

60108
if (sig != null) this.sig = new Signature(sig);
61109
this.msig = msig;
@@ -124,11 +172,7 @@ public boolean verify(Address singleSigner) throws NoSuchAlgorithmException {
124172
return false;
125173
}
126174

127-
try {
128-
Logic.checkProgram(this.logic, this.args);
129-
} catch (Exception ex) {
130-
return false;
131-
}
175+
sanityCheckProgram(this.logic);
132176

133177
PublicKey pk;
134178
try {

src/main/java/com/algorand/algosdk/logic/Logic.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
/**
1515
* Logic class provides static checkProgram function
1616
* that can be used for client-side program validation for size and execution cost.
17+
*
18+
* @deprecated this class is deprecated for relying on metadata (`langspec.json`) that
19+
* does not accurately represent opcode behavior across program versions.
1720
*/
21+
@Deprecated
1822
public class Logic {
1923

2024
private static final int MAX_COST = 20000;
@@ -103,7 +107,7 @@ protected static class ByteConstBlock {
103107
* Each byte in a varint, except the last byte, has the most significant
104108
* bit (msb) set – this indicates that there are further bytes to come.
105109
* The lower 7 bits of each byte are used to store the two's complement
106-
* representation of the number in groups of 7 bits, least significant
110+
* representation of the number in groups of 7 bits, the least significant
107111
* group first.
108112
* https://developers.google.com/protocol-buffers/docs/encoding
109113
* @param value being serialized
@@ -128,7 +132,7 @@ public static byte[] putUVarint(int value) {
128132
* Given a varint, get the integer value
129133
* @param buffer serialized varint
130134
* @param bufferOffset position in the buffer to start reading from
131-
* @return pair of values in in array: value, read size
135+
* @return pair of values in an array: value, read size
132136
*/
133137
public static VarintResult getUVarint(byte [] buffer, int bufferOffset) {
134138
int x = 0;
@@ -164,6 +168,7 @@ public static boolean checkProgram(byte[] program, List<byte[]> args) throws IOE
164168

165169
/**
166170
* Performs basic program validation: instruction count and program cost
171+
*
167172
* @param program Program to validate
168173
* @param args Program arguments to validate
169174
* @return boolean

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,16 @@ public class Transaction implements Serializable {
162162
@JsonProperty("apep")
163163
public Long extraPages = 0L;
164164

165+
/* state proof fields */
166+
@JsonProperty("sptype")
167+
public Integer stateProofType = null;
168+
169+
@JsonProperty("sp")
170+
public Map<String,Object> stateProof = null;
171+
172+
@JsonProperty("spmsg")
173+
public Map<String,Object> stateProofMessage = null;
174+
165175
/**
166176
* Create a payment transaction
167177
* @param fromAddr source address
@@ -722,7 +732,7 @@ private Transaction(@JsonProperty("type") Type type,
722732
}
723733

724734
/**
725-
* Constructor which takes all the fields of Transaction except for nonpart and state proof.
735+
* Constructor which takes all the fields of Transaction except for nonpart.
726736
* For details about which fields to use with different transaction types, refer to the developer documentation:
727737
* https://developer.algorand.org/docs/reference/transactions/#asset-transfer-transaction
728738
*/
@@ -1250,7 +1260,8 @@ public enum Type {
12501260
AssetConfig("acfg"),
12511261
AssetTransfer("axfer"),
12521262
AssetFreeze("afrz"),
1253-
ApplicationCall("appl");
1263+
ApplicationCall("appl"),
1264+
StateProof("stpf");
12541265

12551266
private static Map<String, Type> namesMap = new HashMap<String, Type>(6);
12561267

0 commit comments

Comments
 (0)