Skip to content

Commit

Permalink
Problem: test_periodic_fee_allowance occasionally fails on GH Actions (
Browse files Browse the repository at this point in the history
…Fix crypto-org-chain#626) (crypto-org-chain#638)

Solution:

Wait for latest block time to pass transaction block time plus grant period, instead of sleeping for the grant period amount of time
  • Loading branch information
macong-cdc authored Aug 31, 2021
1 parent b4b4d97 commit ff47723
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
26 changes: 21 additions & 5 deletions integration_tests/test_feegrant.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import datetime
from time import sleep

import pytest
from dateutil.parser import isoparse

from .utils import (
BASECRO_DENOM,
SUCCESS_CODE,
grant_fee_allowance,
query_block_info,
revoke_fee_grant,
transfer,
wait_for_block,
wait_for_block_time,
)

pytestmark = pytest.mark.normal
Expand Down Expand Up @@ -153,15 +156,21 @@ def test_periodic_fee_allowance(cluster):
)

for _ in range(number_of_periods):
transfer(
tx = transfer(
cluster,
fee_grantee_address,
receiver_address,
"%s%s" % (transaction_coins, BASECRO_DENOM),
fees="%s%s" % (fee_coins, BASECRO_DENOM),
fee_account=fee_granter_address,
)
sleep(period)
wait_for_block(cluster, int(tx["height"]))
block_info = query_block_info(cluster, tx["height"])
wait_for_block_time(
cluster,
isoparse(block_info["block"]["header"]["time"])
+ datetime.timedelta(seconds=period),
)

assert (
cluster.balance(fee_granter_address)
Expand Down Expand Up @@ -204,7 +213,7 @@ def test_exceed_period_limit_should_not_affect_the_next_period(cluster):
period=period,
)

transfer(
tx = transfer(
cluster,
fee_grantee_address,
receiver_address,
Expand All @@ -222,7 +231,14 @@ def test_exceed_period_limit_should_not_affect_the_next_period(cluster):
fee_account=fee_granter_address,
)
assert failed_tx["code"] != SUCCESS_CODE, "should fail as fee exceeds period limit"
sleep(period)

wait_for_block(cluster, int(tx["height"]))
block_info = query_block_info(cluster, tx["height"])
wait_for_block_time(
cluster,
isoparse(block_info["block"]["header"]["time"])
+ datetime.timedelta(seconds=period),
)

transfer(
cluster,
Expand Down
11 changes: 11 additions & 0 deletions integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,17 @@ def query_command(cli, *k_options, i=0, **kv_options):
)


def query_block_info(cli, height, i=0):
return json.loads(
cli.cosmos_cli(i).raw(
"query",
"block",
height,
home=cli.cosmos_cli(i).data_dir,
)
)


@throw_error_for_non_success_code
def delegate_amount(
cli, validator_address, amount, from_, *k_options, i=0, **kv_options
Expand Down

0 comments on commit ff47723

Please sign in to comment.