Skip to content
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
23cd772
Revise tests
algochoi Jun 27, 2022
d951d75
Revise and delete v1 algod steps and add devmode helpers
algochoi Jul 8, 2022
b4bba52
Change testing branch
algochoi Jul 8, 2022
a30a72f
Formatting
algochoi Jul 8, 2022
4959a47
Use randint instead of randbytes due to 3.8 support
algochoi Jul 8, 2022
1427eff
Revert "Revise and delete v1 algod steps and add devmode helpers"
algochoi Jul 13, 2022
8cb4e89
Make v1 tests work again
algochoi Jul 13, 2022
3db1248
Merge branch 'develop' into dev-mode-testing
algochoi Jul 13, 2022
93e56c8
Change testing branch
algochoi Jul 13, 2022
d62894d
Merge branch 'develop' into dev-mode-testing
algochoi Jul 13, 2022
c20a0e8
Delete debug print statements
algochoi Jul 15, 2022
884473f
Increase timeout and add back imports
algochoi Jul 15, 2022
26772d0
Change circle configs to increase timeout
algochoi Jul 18, 2022
f7d13e4
Delete v1 integration tests just to see passing CI
algochoi Jul 18, 2022
a0135b3
Revert v1 tests and add wait times
algochoi Jul 18, 2022
7ad3bf7
Change how txids are retrieved
algochoi Jul 18, 2022
70c034b
Fix v1 steps again
algochoi Jul 18, 2022
1fc2047
Use v1 functions
algochoi Jul 18, 2022
7fa997b
Try fixing v1 tests
algochoi Jul 18, 2022
f564238
Skip v1 step when waiting for certain transactions to go through
algochoi Jul 19, 2022
49a8409
Revert no output in CI
algochoi Jul 19, 2022
ac3ef79
Disable v1 rekey test and some flaky v1 algod functions on dev mode
algochoi Jul 19, 2022
c90aa85
Delete redundant assert
algochoi Jul 19, 2022
8f252be
Initialize dev mode accounts to prevent rekeying woes
algochoi Jul 20, 2022
d6993ad
Refactor some names and delete extra unused lines
algochoi Jul 21, 2022
db8ac36
Add some comments, refactor some variables, and change wait rounds to…
algochoi Jul 21, 2022
08d61a1
Add env variable to use dev mode network
algochoi Jul 26, 2022
227bee1
Rekey in separate account
algochoi Jul 26, 2022
0b9c6f1
Fix amounts to proportional amount and rename burn txns
algochoi Jul 27, 2022
3f11057
Isolate dev account in v2 tests
algochoi Jul 27, 2022
03582d3
Lower initial dev mode algo limit to avoid overspending
algochoi Jul 27, 2022
6fd5fd9
Minimize use of transactions to advance rounds in #360 (#365)
michaeldiamant Jul 28, 2022
e444168
Wait for blocks using sleep instead of relying on status_after v1 api
algochoi Jul 28, 2022
f37d018
Lets do some formatting
algochoi Jul 28, 2022
7b8e0ca
Bring back transaction check in v1 step
algochoi Jul 28, 2022
748084c
Revert setting network in run_integration script
algochoi Jul 29, 2022
44c1662
Rename rekeying integ test
algochoi Aug 1, 2022
485fdb4
Revert branch back to master
algochoi Aug 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion run_integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pushd $rootdir

# Reset test harness
rm -rf test-harness
git clone --single-branch --branch master https://github.com/algorand/algorand-sdk-testing.git test-harness
git clone --single-branch --branch devmodenet https://github.com/algorand/algorand-sdk-testing.git test-harness

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Related SDK Testing PR: algorand/algorand-sdk-testing#206


## Copy feature files into the project resources
mkdir -p tests/features
Expand Down
11 changes: 5 additions & 6 deletions tests/steps/account_v2_steps.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from behave import given, then, when
from typing import Union

from algosdk import account, encoding, logic
from algosdk import account, constants, encoding, logic
from algosdk.future import transaction

import tests.steps.other_v2_steps
from behave import given, then, when
from tests.steps.other_v2_steps import dev_mode_wait_for_confirmation


def fund_account_address(
Expand All @@ -19,7 +18,7 @@ def fund_account_address(
)
signed_payment = context.wallet.sign_transaction(payment)
context.app_acl.send_transaction(signed_payment)
transaction.wait_for_confirmation(context.app_acl, payment.get_txid(), 10)
dev_mode_wait_for_confirmation(context, payment.get_txid(), 10)


@when(
Expand Down Expand Up @@ -454,7 +453,7 @@ def create_transient_and_fund(context, transient_fund_amount):
)
signed_payment = context.wallet.sign_transaction(payment)
context.app_acl.send_transaction(signed_payment)
transaction.wait_for_confirmation(context.app_acl, payment.get_txid(), 10)
dev_mode_wait_for_confirmation(context, payment.get_txid(), 10)


@then(
Expand Down
19 changes: 11 additions & 8 deletions tests/steps/application_v2_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
import json
import re

from behave import given, step, then, when
import pytest

from algosdk import abi, atomic_transaction_composer, encoding, mnemonic
from algosdk.abi.contract import NetworkInfo
from algosdk.error import (
ABITypeError,
IndexerHTTPError,
AtomicTransactionComposerError,
IndexerHTTPError,
)
from algosdk.future import transaction

from tests.steps.other_v2_steps import read_program
from behave import given, step, then, when
from tests.steps.other_v2_steps import (
dev_mode_wait_for_confirmation,
read_program,
burn_algo_transactions,
)


def operation_string_to_enum(operation):
Expand Down Expand Up @@ -406,16 +408,17 @@ def remember_app_id(context):
def wait_for_app_txn_confirm(context):
sp = context.app_acl.suggested_params()
last_round = sp.first
# Send some transactions to advance block state in dev mode so we can
# check the status after block `last_round + 2`.
burn_algo_transactions(context, 3)
context.app_acl.status_after_block(last_round + 2)
if hasattr(context, "acl"):
assert "type" in context.acl.transaction_info(
context.transient_pk, context.app_txid
)
assert "type" in context.acl.transaction_by_id(context.app_txid)
else:
transaction.wait_for_confirmation(
context.app_acl, context.app_txid, 10
)
dev_mode_wait_for_confirmation(context, context.app_txid, 10)


@given("an application id {app_id}")
Expand Down
60 changes: 43 additions & 17 deletions tests/steps/other_v2_steps.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
import base64
import json
import os
import urllib
import random
import unittest
import urllib
from datetime import datetime
from pathlib import Path
from urllib.request import Request, urlopen

from behave import (
given,
when,
then,
register_type,
step,
) # pylint: disable=no-name-in-module

from glom import glom
import parse

from algosdk import dryrun_results, encoding, error, mnemonic, source_map
from algosdk import (
constants,
dryrun_results,
encoding,
error,
mnemonic,
source_map,
)
from algosdk.error import AlgodHTTPError
from algosdk.future import transaction
from algosdk.testing.dryrun import DryrunTestCaseMixin
from algosdk.v2client import *
from algosdk.v2client.models import (
DryrunRequest,
DryrunSource,
Account,
ApplicationLocalState,
DryrunRequest,
DryrunSource,
)
from algosdk.testing.dryrun import DryrunTestCaseMixin

from tests.steps.steps import algod_port, token as daemon_token
from behave import register_type # pylint: disable=no-name-in-module
from behave import given, step, then, when
from glom import glom
from tests.steps.steps import algod_port
from tests.steps.steps import token as daemon_token


@parse.with_pattern(r".*")
Expand Down Expand Up @@ -97,6 +98,31 @@ def read_program(context, path):
return read_program_binary(path)


# Send transactions to progress block numbers on dev mode.
def burn_algo_transactions(context, num_txns=1):
sp = context.app_acl.suggested_params()
for _ in range(num_txns):
payment = transaction.PaymentTxn(
context.accounts[0],
sp,
constants.ZERO_ADDRESS,
random.randint(100000, 900000),
Comment thread
tzaffi marked this conversation as resolved.
Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@algochoi Optionally, I propose configuring the upper bound proportional to the funding amount. Intent is to avoid generating a value that's too large if/when the funding amount changes.

Here's the Java SDK analog: algorand/java-algorand-sdk@3390a6d.

Feel welcomed to resolve as is.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point - Added proportional funding amounts in latest commit 3f11057

)
signed_payment = context.wallet.sign_transaction(payment)
context.app_acl.send_transaction(signed_payment)
# Wait and confirm that the zero payment succeeded.
transaction.wait_for_confirmation(
Comment thread
tzaffi marked this conversation as resolved.
Outdated
context.app_acl, payment.get_txid(), 5
)


# To prevent excess waiting, send a zero payment transaction before
# the wait_for_confirmation function in dev mode.
def dev_mode_wait_for_confirmation(context, txid, rounds):
Comment thread
tzaffi marked this conversation as resolved.
Outdated
burn_algo_transactions(context)
transaction.wait_for_confirmation(context.app_acl, txid, rounds)


@given("mock server recording request paths")
def setup_mockserver(context):
context.url = "http://127.0.0.1:" + str(context.path_server_port)
Expand Down
70 changes: 53 additions & 17 deletions tests/steps/steps.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,57 @@
from behave import given, when, then
import base64
from algosdk import kmd
from algosdk.future import transaction
from algosdk import encoding
from algosdk import algod
from algosdk import account
from algosdk import mnemonic
from algosdk import wallet
from algosdk import auction
from algosdk import util
from algosdk import constants
from algosdk import logic
from algosdk.future import template
import os
import random
from datetime import datetime
import hashlib

from algosdk import (
Comment thread
tzaffi marked this conversation as resolved.
account,
algod,
auction,
constants,
encoding,
kmd,
logic,
mnemonic,
util,
wallet,
)
from algosdk.future import transaction
from behave import given, then, when
from nacl.signing import SigningKey

token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
algod_port = 60000
kmd_port = 60001


# Initialize dev mode accounts.
def initialize_dev_mode_account(context):
context.dev_sk, context.dev_pk = account.generate_account()
payment = transaction.PaymentTxn(
sender=context.accounts[0],
sp=context.acl.suggested_params_as_object(),
receiver=context.dev_pk,
amt=10_000_000,
Comment thread
tzaffi marked this conversation as resolved.
Outdated
)
signed_payment = context.wallet.sign_transaction(payment)
context.acl.send_transaction(signed_payment)


# Send a zero payment transaction
def burn_algo_transactions(context, num_txns=1):
if not hasattr(context, "dev_pk"):
initialize_dev_mode_account(context)
for _ in range(num_txns):
payment = transaction.PaymentTxn(
sender=context.dev_pk,
sp=context.acl.suggested_params_as_object(),
receiver=constants.ZERO_ADDRESS,
amt=random.randint(100000, 900000),
)
signed_payment = payment.sign(context.dev_sk)
context.acl.send_transaction(signed_payment)


@when("I create a wallet")
def create_wallet(context):
context.wallet_name = "Walletpy"
Expand Down Expand Up @@ -225,13 +254,15 @@ def status(context):

@when("I get status after this block")
def status_block(context):
burn_algo_transactions(context)
context.status_after = context.acl.status_after_block(
context.status["lastRound"]
)


@then("I can get the block info")
def block(context):
burn_algo_transactions(context)
context.block = context.acl.block_info(context.status["lastRound"] + 1)


Expand Down Expand Up @@ -320,6 +351,7 @@ def algod_client(context):
algod_address = "http://localhost:" + str(algod_port)
context.acl = algod.AlgodClient(token, algod_address)
if context.acl.status()["lastRound"] < 2:
burn_algo_transactions(context, 2)
context.acl.status_after_block(2)


Expand Down Expand Up @@ -347,6 +379,10 @@ def default_txn(context, amt, note):
)
context.pk = context.accounts[0]

# Initialize dev mode accounts
if not hasattr(context, "dev_pk"):
initialize_dev_mode_account(context)


@given('default multisig transaction with parameters {amt} "{note}"')
def default_msig_txn(context, amt, note):
Expand Down Expand Up @@ -404,19 +440,18 @@ def send_msig_txn(context):

@then("the transaction should go through")
def check_txn(context):
last_round = context.acl.status()["lastRound"]
burn_algo_transactions(context)
assert "type" in context.acl.pending_transaction_info(
context.txn.get_txid()
)
context.acl.status_after_block(last_round + 2)
assert "type" in context.acl.transaction_info(
context.txn.sender, context.txn.get_txid()
)
assert "type" in context.acl.transaction_by_id(context.txn.get_txid())
Comment thread
algochoi marked this conversation as resolved.


@then("I can get the transaction by ID")
def get_txn_by_id(context):
burn_algo_transactions(context, 3)
context.acl.status_after_block(context.last_round + 2)
assert "type" in context.acl.transaction_by_id(context.txn.get_txid())

Expand Down Expand Up @@ -493,6 +528,7 @@ def check_save_txn(context):
stx = transaction.retrieve_from_file(dir_path + "/temp/txn.tx")[0]
txid = stx.transaction.get_txid()
last_round = context.acl.status()["lastRound"]
burn_algo_transactions(context, 3)
context.acl.status_after_block(last_round + 2)
assert context.acl.transaction_info(stx.transaction.sender, txid)

Expand Down