Skip to content

Commit

Permalink
local testscript
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangsu committed Aug 22, 2022
1 parent 0427e98 commit a2a3c52
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main/java/com/algorand/algosdk/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,6 @@ public static VarintResult getUVarint(byte [] buffer, int bufferOffset) {
* @param program
*/
public static void sanityCheckProgram(final byte[] program) {
if (Base64.isBase64(program))
throw new IllegalArgumentException("program should not be b64 encoded");

boolean isAddress = false;
try {
new Address(new String(program));
Expand All @@ -184,6 +181,9 @@ public static void sanityCheckProgram(final byte[] program) {
}
if (isAddress)
throw new IllegalArgumentException("requesting program bytes, but get Algorand address");

if (Base64.isBase64(program))
throw new IllegalArgumentException("program should not be b64 encoded");
}

@Deprecated
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/com/algorand/algosdk/logic/TestLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.collect.ImmutableList;
import org.junit.jupiter.api.Test;

import java.nio.charset.StandardCharsets;
import java.util.*;

import static com.algorand.algosdk.logic.Logic.*;
Expand Down Expand Up @@ -447,4 +448,23 @@ public void testCheckProgramV6() throws Exception {
assertThat(valid).isTrue();
}
}

@Test
public void testSanityCheckProgram() {
{
// pass in address
String addressNotProg = "DN7MBMCL5JQ3PFUQS7TMX5AH4EEKOBJVDUF4TCV6WERATKFLQF4MQUPZTA";
assertThatThrownBy(() -> sanityCheckProgram(addressNotProg.getBytes(StandardCharsets.UTF_8)))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("requesting program bytes, but get Algorand address");
}

{
// pass in b64 encoded msg
String exampleB64 = "gqRtc2lng6ZzdWJzaWeTgqJwa8QgG37AsEvqYbeWkJfmy/QH4QinBTUdC8mKvrEiCairgXihc8RAdvZ3y9GsInBPutdwKc7Jy+an13CcjSV1lcvRAYQKYOxXwfgT5B/mK14R57ueYJTYyoDO8zBY6kQmBalWkm95AIGicGvEIAljMglTc4nwdWcRdzmRx9A+G3PIxPUr9q/wGqJc+cJxgaJwa8Qg5/D4TQaBHfnzHI2HixFV9GcdUaGFwgCQhmf0SVhwaKGjdGhyAqF2AaN0eG6Jo2FtdM0TiKNmZWXOAANPqKJmds4ADtbco2dlbq10ZXN0bmV0LXYzMS4womx2zgAO2sSkbm90ZcQItFF5Ofz60nGjcmN2xCAbfsCwS+pht5aQl+bL9AfhCKcFNR0LyYq+sSIJqKuBeKNzbmTEII2StImQAXOgTfpDWaNmamr86ixCoF3Zwfc+66VHgDfppHR5cGWjcGF5";
assertThatThrownBy(() -> sanityCheckProgram(exampleB64.getBytes(StandardCharsets.UTF_8)))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("program should not be b64 encoded");
}
}
}

0 comments on commit a2a3c52

Please sign in to comment.