Skip to content

Commit 98b527d

Browse files
Improve flaky contract test (#1025)
* Improve flaky contract test Sometimes the sleep takes longer than the button lifetime, which causes the button to die and subsequent clicks to fail. This setup where we click twice and then measure how long each click took should be more reliabale. * Use falttened branch name in build and push cliain workflow --------- Co-authored-by: Marcin <marcin.radecki@cardinals.cc>
1 parent 7d4b655 commit 98b527d

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

.github/workflows/build-and-push-cliain.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ jobs:
5858
IMAGE_NAME: ${{ matrix.runtime == 'standard' && 'cliain' || 'cliain-liminal' }}
5959
TAG: >
6060
${{ matrix.runtime == 'standard' &&
61-
(steps.get-ref-properties.outputs.branch == 'main' && 'latest' ||
62-
steps.get-ref-properties.outputs.branch) ||
61+
(steps.get-ref-properties.outputs.branch-name-flattened == 'main' && 'latest' ||
62+
steps.get-ref-properties.outputs.branch-name-flattened) ||
6363
matrix.runtime == 'liminal' && steps.get-ref-properties.outputs.sha }}
6464
uses: docker/build-push-action@v3.3.0
6565
with:

e2e-tests/src/test/button_game/mod.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -458,26 +458,33 @@ async fn button_game_play<F: Fn(u128, u128)>(
458458
button.press(&sign(&conn, player)).await?;
459459

460460
let event = assert_recv_id(&mut events, "ButtonPressed").await;
461-
let_assert!(Some(&Value::UInt(early_presser_score)) = event.data.get("score"));
461+
let_assert!(Some(&Value::UInt(first_presser_score)) = event.data.get("score"));
462462
assert!(event.data.get("by") == Some(&Value::Literal(player.account_id().to_string())));
463-
assert!(reward_token.balance_of(&conn, player.account_id()).await? == early_presser_score);
464-
assert!(early_presser_score > 0);
463+
assert!(reward_token.balance_of(&conn, player.account_id()).await? == first_presser_score);
464+
assert!(first_presser_score > 0);
465465
assert!(ticket_token.balance_of(&conn, player.account_id()).await? == 1);
466466
assert!(
467467
ticket_token
468468
.balance_of(&conn, &button.as_ref().into())
469469
.await?
470470
== old_button_balance + 1
471471
);
472-
let_assert!(Some(&Value::UInt(pressed_at)) = event.data.get("when"));
473-
let time_to_sleep = pressed_at - reset_at + 3;
472+
let_assert!(Some(&Value::UInt(first_press_at)) = event.data.get("when"));
474473

475-
info!("Waiting {} seconds before pressing again", time_to_sleep);
476-
sleep(Duration::from_secs(time_to_sleep as u64)).await;
474+
info!("Waiting before pressing again");
475+
sleep(Duration::from_secs(3)).await;
477476

478477
button.press(&sign(&conn, player)).await?;
479478
let event = assert_recv_id(&mut events, "ButtonPressed").await;
480-
let_assert!(Some(&Value::UInt(late_presser_score)) = event.data.get("score"));
479+
let_assert!(Some(&Value::UInt(second_presser_score)) = event.data.get("score"));
480+
let_assert!(Some(&Value::UInt(second_press_at)) = event.data.get("when"));
481+
let (early_presser_score, late_presser_score) =
482+
if (first_press_at - reset_at) < (second_press_at - first_press_at) {
483+
(first_presser_score, second_presser_score)
484+
} else {
485+
(second_presser_score, first_presser_score)
486+
};
487+
481488
score_check(early_presser_score, late_presser_score);
482489
let total_score = early_presser_score + late_presser_score;
483490
assert!(reward_token.balance_of(&conn, player.account_id()).await? == total_score);

0 commit comments

Comments
 (0)