Skip to content

Commit d223913

Browse files
authored
Testing Contract to Contract Functionality on the SDK's (#156)
1 parent b3f559f commit d223913

File tree

11 files changed

+749
-134
lines changed

11 files changed

+749
-134
lines changed

README.md

Lines changed: 94 additions & 54 deletions
Large diffs are not rendered by default.

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ services:
135135
volumes:
136136
- ./docker/indexer/init-scripts:/docker-entrypoint-initdb.d
137137
ports:
138-
- 5433:5432
138+
- 65432:5432
139139
networks:
140140
- sdk-harness
141141
environment:

docker/algod/source/Dockerfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.13.12
1+
FROM golang:1.16.11
22

33
ARG URL=https://github.com/algorand/go-algorand
44
ARG BRANCH=master
@@ -23,12 +23,12 @@ RUN git clone --single-branch --branch "${BRANCH}" "${URL}" && \
2323

2424
# Configure private network
2525
RUN python3 /tmp/docker/algod/setup.py configure \
26-
--bin-dir "$BIN_DIR" \
27-
--network-dir /opt/testnetwork \
28-
--network-template /tmp/network_config/future_template.json \
29-
--network-token aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
30-
--algod-port 60000 \
31-
--kmd-port 60001
26+
--bin-dir "$BIN_DIR" \
27+
--network-dir /opt/testnetwork \
28+
--network-template /tmp/network_config/future_template.json \
29+
--network-token aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
30+
--algod-port 60000 \
31+
--kmd-port 60001
3232

3333
# Start algod
3434
CMD ["/usr/bin/env", "bash", "-c", "python3 /tmp/docker/algod/setup.py start --bin-dir \"$BIN_DIR\" --network-dir \"/opt/testnetwork\" --copy-genesis-to \"/genesis-file\""]

features/integration/applications.feature

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Feature: Applications
1212
Given I create a new transient account and fund it with 100000000 microalgos.
1313
# Application create with extra pages should succeed with expected message.
1414
And I build an application transaction with the transient account, the current application, suggested params, operation "create", approval-program "programs/big_app_program.teal.tok", clear-program "programs/big_app_program.teal.tok", global-bytes <global-bytes>, global-ints 0, local-bytes <local-bytes>, local-ints 0, app-args "", foreign-apps "", foreign-assets "", app-accounts "", extra-pages 3
15-
And I sign and submit the transaction, saving the txid. If there is an error it is "logic eval error: pc=704 dynamic cost budget exceeded, executing intc_1: remaining budget is 700 but program cost was 701".
15+
And I sign and submit the transaction, saving the txid. If there is an error it is "logic eval error: pc=704 dynamic cost budget exceeded, executing intc_1: local program cost was 700. Details: pc=704, opcodes=intc_1 // 1".
16+
1617
# Create application
1718
# depends on the transient account, and also the application id.
1819
# Use suggested params
@@ -21,8 +22,9 @@ Feature: Applications
2122
And I sign and submit the transaction, saving the txid. If there is an error it is "".
2223
And I wait for the transaction to be confirmed.
2324
And I remember the new application ID.
25+
Then I get the account address for the current application and see that it matches the app id's hash
2426
# Update approval program to 'loccheck'
25-
And I build an application transaction with the transient account, the current application, suggested params, operation "update", approval-program "<program>", clear-program "programs/one.teal.tok", global-bytes 0, global-ints 0, local-bytes 0, local-ints 0, app-args "", foreign-apps "", foreign-assets "", app-accounts "", extra-pages 0
27+
Given I build an application transaction with the transient account, the current application, suggested params, operation "update", approval-program "<program>", clear-program "programs/one.teal.tok", global-bytes 0, global-ints 0, local-bytes 0, local-ints 0, app-args "", foreign-apps "", foreign-assets "", app-accounts "", extra-pages 0
2628
And I sign and submit the transaction, saving the txid. If there is an error it is "".
2729
And I wait for the transaction to be confirmed.
2830
# OptIn - with error (missing argument)

features/integration/c2c.feature

Lines changed: 224 additions & 0 deletions
Large diffs are not rendered by default.

features/integration/compile.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,13 @@ Feature: Compile
1010
| program | status | result | hash |
1111
| "programs/one.teal" | 200 | "AiABASI=" | "YOE6C22GHCTKAN3HU4SE5PGIPN5UKXAJTXCQUPJ3KKF5HOAH646MKKCPDA" |
1212
| "programs/invalid.teal" | 400 | "" | "" |
13+
14+
15+
Scenario Outline: Teals compile to their associated binary
16+
When I compile a teal program <teal>
17+
Then base64 decoding the response is the same as the binary <program>
18+
Examples:
19+
| teal | program |
20+
| "programs/one.teal" | "programs/one.teal.tok" |
21+
| "programs/zero.teal" | "programs/zero.teal.tok" |
22+
| "programs/abi_method_call.teal" | "programs/abi_method_call.teal.tok" |

features/integration/template.feature

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// <<<< WARNING: For demo purposes only >>>>
2+
// Do not use in any applications that require unpredictable randomness.
3+
// (As of Jan 2022) To achieve secure randomness, consider following an approach such as: https://github.com/ori-shem-tov/vrf-oracle
4+
5+
// TODO: disallow updates, optins, etc.
6+
7+
#pragma version 6
8+
txn ApplicationID
9+
bz create // yes, we can create this app
10+
11+
txn ApplicationArgs 0
12+
method "randInt(uint64)(uint64,byte[17])"
13+
==
14+
assert // except for create, only allow calling method randInt()
15+
16+
global Round
17+
itob
18+
pushbytes "#"
19+
concat
20+
pushbytes "counter"
21+
app_global_get
22+
dup
23+
24+
pushint 1
25+
+
26+
pushbytes "counter"
27+
swap
28+
app_global_put
29+
itob
30+
concat // >>> itob(round)|#|itob(counter)
31+
dup
32+
sha512_256
33+
pushint 0
34+
extract_uint64
35+
txn ApplicationArgs 1
36+
btoi
37+
% // TODO: slightly better if try again in the unlikely case that 1 << 64 + A % B < A + B
38+
itob
39+
swap
40+
concat // >>> itob(randInt)|itob(round)|#|itob(counter)
41+
byte 0x151f7c75 // return code
42+
swap
43+
concat
44+
log
45+
46+
b finish
47+
48+
create:
49+
pushbytes "counter"
50+
pushint 0
51+
app_global_put
52+
53+
finish:
54+
int 1
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// TODO: disallow updates, optins, etc.
2+
3+
// Input: a string s such as "hello random"
4+
// Output: a byte in s picked with index of uniform randomness
5+
6+
// 1. n := len(s)
7+
// 2. r, w := FakeRandom.randInt(n)
8+
// 3. c := substring n n+1
9+
// 4. return c, w
10+
11+
#pragma version 6
12+
txn ApplicationID
13+
bz finish // creating ok
14+
15+
txn ApplicationArgs 0
16+
method "randElement(string,application)(byte,byte[17])"
17+
==
18+
assert // other than create, only the app call is allowed
19+
20+
itxn_begin
21+
int appl
22+
itxn_field TypeEnum
23+
24+
txn Applications 1 // FakeRandom
25+
itxn_field ApplicationID
26+
27+
method "randInt(uint64)(uint64,byte[17])"
28+
itxn_field ApplicationArgs
29+
30+
txn ApplicationArgs 1
31+
len
32+
pushint 2
33+
- // subtract 2 from length for encoding prefix
34+
itob
35+
itxn_field ApplicationArgs
36+
itxn_submit
37+
38+
// assert a single log so we know where to look for return val:
39+
pushint 0
40+
itxn NumLogs
41+
pushint 1
42+
==
43+
assert
44+
45+
itxna Logs 0
46+
// >>> return|uint64|byte[17]|
47+
48+
// dup
49+
// pushbytes "debug logs received--->"
50+
// log
51+
// log
52+
// >>> return|uint64|byte[17]|
53+
54+
dup
55+
extract 12 0 // the witness
56+
swap
57+
// >>> byte[17] <-- return|uint64|byte[17]|
58+
59+
extract 4 8 // the randInt
60+
btoi
61+
// >>> byte[17] <-- randInt
62+
63+
txn ApplicationArgs 1
64+
// >>> byte[17] <-- randInt <-- len|input_string
65+
66+
extract 2 0 // the input string
67+
swap
68+
// >>> byte[17] <-- input_string <-- randInt
69+
70+
pushint 1
71+
extract3
72+
// >>> byte[17] <-- randByte
73+
74+
pushbytes 0x151f7c75 // return code
75+
swap
76+
// >>> byte[17] <-- return <-- randByte
77+
78+
concat
79+
// >>> byte[17] <-- return|randByte
80+
81+
swap
82+
concat
83+
// >>> return|randByte|byte[17]
84+
85+
log
86+
// <<<EMPTY>>>
87+
88+
finish:
89+
int 1
90+
return
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#pragma version 6
2+
int 6

0 commit comments

Comments
 (0)