Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Boxes Indexer Integration test #382

Merged
merged 15 commits into from
Sep 14, 2022
2 changes: 1 addition & 1 deletion .test-env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Configs for testing repo download:
SDK_TESTING_URL="https://github.com/algorand/algorand-sdk-testing"
SDK_TESTING_BRANCH="feature/box-storage"
SDK_TESTING_BRANCH="ahangsu/indexer-integration-boxes"
ahangsu marked this conversation as resolved.
Show resolved Hide resolved
SDK_TESTING_HARNESS="test-harness"

VERBOSE_HARNESS=0
Expand Down
1 change: 1 addition & 0 deletions tests/integration.tags
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@algod
@applications
@applications.boxes
@applications.boxes_indexer_confirmed
@applications.verified
@assets
@auction
Expand Down
72 changes: 57 additions & 15 deletions tests/steps/application_v2_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@
import json
import re
import time

import secrets
import pytest
from algosdk import abi, atomic_transaction_composer, encoding, mnemonic

from algosdk import (
abi,
atomic_transaction_composer,
encoding,
mnemonic,
constants,
)
from algosdk.abi.contract import NetworkInfo
from algosdk.error import (
ABITypeError,
AtomicTransactionComposerError,
)
from algosdk.future import transaction
from behave import given, step, then, when
from tests.steps.other_v2_steps import (
read_program,
)
from tests.steps.other_v2_steps import read_program


def operation_string_to_enum(operation):
Expand Down Expand Up @@ -371,6 +376,7 @@ def build_app_txn_with_transient(
boxes = split_and_process_boxes(boxes)

sp = context.app_acl.suggested_params()

context.app_transaction = transaction.ApplicationCallTxn(
sender=context.transient_pk,
sp=sp,
Expand Down Expand Up @@ -1132,16 +1138,28 @@ def check_found_method_or_error(context, methodsig, error: str = None):


@then(
'the contents of the box with name "{box_name}" in the current application should be "{box_value:MaybeString}". If there is an error it is "{error_string:MaybeString}".'
'according to "{from_client}", the contents of the box with name "{box_name}" in the current application should be "{box_value:MaybeString}". If there is an error it is "{error_string:MaybeString}".'
)
def check_box_contents(
context, box_name, box_value: str = None, error_string: str = None
context,
from_client,
box_name,
box_value: str = None,
error_string: str = None,
):
try:
box_name = split_and_process_app_args(box_name)[0]
box_response = context.app_acl.application_box_by_name(
context.current_application_id, box_name
)
if from_client == "algod":
box_response = context.app_acl.application_box_by_name(
context.current_application_id, box_name
)
elif from_client == "indexer":
box_response = context.app_icl.application_box_by_name(
context.current_application_id, box_name
)
else:
assert False, "expecting algod or indexer, get " + from_client
ahangsu marked this conversation as resolved.
Show resolved Hide resolved

actual_name = box_response["name"]
actual_value = box_response["value"]
assert box_name == base64.b64decode(actual_name)
Expand All @@ -1157,13 +1175,21 @@ def check_box_contents(


@then(
'the current application should have the following boxes "{box_names:MaybeString}".'
'according to "{from_client}", the current application should have the following boxes "{box_names:MaybeString}".'
)
def check_all_boxes(context, box_names: str = None):
def check_all_boxes(context, from_client: str, box_names: str = None):
expected_box_names = split_and_process_app_args(box_names)
box_response = context.app_acl.application_boxes(
context.current_application_id
)
if from_client == "algod":
box_response = context.app_acl.application_boxes(
context.current_application_id
)
elif from_client == "indexer":
box_response = context.app_icl.application_boxes(
context.current_application_id
)
else:
assert False, "expecting algod or indexer, get " + from_client
ahangsu marked this conversation as resolved.
Show resolved Hide resolved

actual_box_names = []
for box in box_response["boxes"]:
box = box["name"]
Expand All @@ -1177,3 +1203,19 @@ def check_all_boxes(context, box_names: str = None):
assert set(expected_box_names) == set(
actual_box_names
), f"Expected box names array does not match actual array {expected_box_names} != {actual_box_names}"


@then("I forward {round_num} empty rounds with transient account.")
def forward_n_empty_rounds(context, round_num: int):
sp = context.acl.suggested_params_as_object()
for _ in range(int(round_num)):
dummy_tx = transaction.PaymentTxn(
context.transient_pk,
sp,
constants.ZERO_ADDRESS,
0,
note=secrets.token_bytes(8),
)
dummy_stx = dummy_tx.sign(context.transient_sk)
dummy_txid = context.app_acl.send_transaction(dummy_stx)
transaction.wait_for_confirmation(context.app_acl, dummy_txid, 1)
8 changes: 7 additions & 1 deletion tests/steps/other_v2_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
when,
)
from glom import glom
from tests.steps.steps import algod_port
from tests.steps.steps import algod_port, indexer_port
from tests.steps.steps import token as daemon_token


Expand Down Expand Up @@ -1023,6 +1023,12 @@ def algod_v2_client(context):
context.app_acl = algod.AlgodClient(daemon_token, algod_address)


@given("an indexer v2 client")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👶 - indexer is reborn!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: might be nice to put right next to where algod is defined.

def indexer_v2_client(context):
indexer_address = "http://localhost" + ":" + str(indexer_port)
context.app_icl = indexer.IndexerClient("", indexer_address)


@when('I compile a teal program "{program}"')
def compile_step(context, program):
data = load_resource(program)
Expand Down
1 change: 1 addition & 0 deletions tests/steps/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def parse_string(text):


token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
indexer_port = 59999
ahangsu marked this conversation as resolved.
Show resolved Hide resolved
algod_port = 60000
kmd_port = 60001

Expand Down