Skip to content

Commit

Permalink
PLT-7826 finish choice contract test
Browse files Browse the repository at this point in the history
  • Loading branch information
ladamesny committed Oct 23, 2023
1 parent bfa0f89 commit 046b2cc
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 23 deletions.
3 changes: 2 additions & 1 deletion e2e/config/mappings/page-elements/home.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"contract-input": {"role": "textbox", "name": "contract-input" }
"contract-input": {"role": "textbox", "name": "contract-input" },
"choice-input": {"role": "spinbutton", "name": "choice-input" }
}
44 changes: 34 additions & 10 deletions e2e/src/features/apply-inputs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Feature: As a user, I would like to apply an input on a current contract
As a user I would like to apply an input on a current contract
So that I can proceed through the contract

@dev
Scenario: Creating a deposit with a Lace wallet
Given I configure my lace wallet
And I am on the "home" page
Expand All @@ -30,32 +29,57 @@ Feature: As a user, I would like to apply an input on a current contract
When I click the "checkbox" with "Deposit 0.000001 ₳" text
And I click the "button" with "Make deposit" text And sign the transaction
And I should see "Successfully applied the inputs. Input application transaction awaits to be included in the blockchain." text
And I pause the page

Scenario: Creating a choice with a Lace wallet
Given I am on the "home" page
When I authorize my "lace" wallet
Given I configure my lace wallet
And I am on the "home" page
Then I should see a "heading" with "Choose a wallet" text

When I authorize my lace wallet
Then I should see a "button" with "Create a contract" text

When I click the "button" with "Create a contract" text
And I enter the contents of "../support/contracts/lace-10-2024/choice.json" into the "contract-input" field
And I generate the contract "SimpleChoice" and write it to "/tmp/choice.json"
And I enter the contents of "/tmp/choice.json" into the "contract-input" field

When I click the "button" with "Submit contract" text And sign the transaction
Then I should see a "button" with "Syncing" text
Then I should see the first "button" showing "Syncing" text
And I should see the first "button" showing "Advance" text
And I should see "Successfully created and submitted the contract. Contract transaction awaits to be included in the blockchain." text

Scenario: Creating a notify contract with a Lace wallet
When I click the first "button" with "Advance" text
Then I should see a "button" with "Advance contract" text

When I fill in the "choice-input" input with "1"
When I click the "button" with "Advance contract" text And sign the transaction
Then I should see the first "button" showing "Syncing" text
And I should see the first "button" showing "Advance" text
And I should see "Successfully applied the inputs. Input application transaction awaits to be included in the blockchain." text

@dev
Scenario: Creating a timed-out contract with a Lace wallet
Given I configure my lace wallet
Given I am on the "home" page
When I authorize my "lace" wallet
Then I should see a "heading" with "Choose a wallet" text

When I authorize my lace wallet
Then I should see a "button" with "Create a contract" text

When I click the "button" with "Create a contract" text
And I enter the contents of "../support/contracts/lace-10-2024/notify.json" into the "contract-input" field
And I generate the contract "TimedOutSimpleChoice" and write it to "/tmp/timed-out-choice.json"
And I enter the contents of "/tmp/timed-out-choice.json" into the "contract-input" field

When I click the "button" with "Submit contract" text And sign the transaction
Then I should see a "button" with "Syncing" text
Then I should see the first "button" showing "Syncing" text
And I should see the first "button" showing "Advance" text
And I should see "Successfully created and submitted the contract. Contract transaction awaits to be included in the blockchain." text

When I click the first "button" with "Advance" text
Then I should see a "button" with "Advance contract" text
And I pause the page



# Scenario: Creating a notify contract with a Lace wallet
# Given I am on the "home" page
# When I authorize my "lace" wallet
Expand Down
71 changes: 60 additions & 11 deletions e2e/src/step-definitions/generate-contract.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import playwright from 'playwright';
import * as fs from 'fs';
import { When } from '@cucumber/cucumber';
import { ScenarioWorld } from './setup/world.js';
import { ValidAccessibilityRoles } from '../env/global.js';
import { waitFor } from "../support/wait-for-behavior.js";
import {
inputValue,
} from '../support/html-behavior.js';
import {
Address,
Contract,
datetoTimeout,
} from "@marlowe.io/language-core-v1";
import { MarloweJSON } from "@marlowe.io/adapter/codec";

type ContractName = "SimpleDeposit";
type ContractName = "SimpleDeposit" | "SimpleChoice" | "TimedOutSimpleChoice";

const mkSimpleDeposit = (address: string): Contract => {
const twentyMinutesInMilliseconds = 20 * 60 * 1000;
Expand All @@ -35,6 +27,55 @@ const mkSimpleDeposit = (address: string): Contract => {
};
}

const mkSimpleChoice = (address: string): Contract => {
const twentyMinutesInMilliseconds = 20 * 60 * 1000;
const inTwentyMinutes = datetoTimeout(new Date(Date.now() + twentyMinutesInMilliseconds));
return {
timeout: inTwentyMinutes,
timeout_continuation: "close",
when: [
{ case: {
choose_between:
[{
from: 1n,
to: 2n
}],
for_choice: {
choice_owner: {address: address},
choice_name: "simpleChoice",
}
},
then: "close",
},
]
};
}

const mkTimedOutSimpleChoice = (address: string): Contract => {
const twentyMinutesInMilliseconds = 20 * 60 * 1000;
const inTwentyMinutes = datetoTimeout(new Date(Date.now() - twentyMinutesInMilliseconds));
return {
timeout: inTwentyMinutes,
timeout_continuation: "close",
when: [
{ case: {
choose_between:
[{
from: 1n,
to: 2n
}],
for_choice: {
choice_owner: {address: address},
choice_name: "simpleChoice",
}
},
then: "close",
},
]
};
}


// // And I generate the contract "SimpleDeposit" and write it to "/tmp/deposit.json"
When(
/^I generate the contract "([^"]*)" and write it to "([^"]*)"/,
Expand All @@ -45,8 +86,16 @@ When(
const walletAddress = globalStateManager.getValue("wallet-address");
switch (contractName) {
case "SimpleDeposit":
const contract = mkSimpleDeposit(walletAddress);
globalStateManager.appendValue(fileName, MarloweJSON.stringify(contract, null, 4))
const contract1 = mkSimpleDeposit(walletAddress);
globalStateManager.appendValue(fileName, MarloweJSON.stringify(contract1, null, 4))
break;
case "SimpleChoice":
const contract2 = mkSimpleChoice(walletAddress);
globalStateManager.appendValue(fileName, MarloweJSON.stringify(contract2, null, 4))
break;
case "TimedOutSimpleChoice":
const contract3 = mkTimedOutSimpleChoice(walletAddress);
globalStateManager.appendValue(fileName, MarloweJSON.stringify(contract3, null, 4))
break;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Component/ApplyInputs.purs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import Data.Maybe (Maybe(..))
import Data.Monoid as Monoid
import Data.Time.Duration (Milliseconds(..), Seconds(..))
import Data.Traversable (for)
import Data.Undefined.NoProblem as NoProblem
import Data.Validation.Semigroup (V(..))
import Effect (Effect)
import Effect.Aff (Aff)
Expand Down Expand Up @@ -254,7 +255,7 @@ mkChoiceFormComponent = do

formSpec = evalBuilder' $ ado
choice <- choiceField { choices, validator, touched: true, initial: "0" }
value <- intInput {}
value <- intInput { role: NoProblem.opt "textarea", "aria-label": NoProblem.opt "choice-input" }
in
{ choice, value }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ renderTextInput
, max :: Opt Number
, min :: Opt Number
, step :: Opt Number
, role :: Opt String
, "aria-label" :: Opt String
, "aria-labelledby" :: Opt String
}
-> InputState String
-> JSX
Expand Down Expand Up @@ -292,6 +295,9 @@ renderTextInput
, step: props.step
, min: props.min
, max: props.max
, role: props.role
, "aria-label": props."aria-label"
, "aria-labelledby": props."aria-labelledby"
}
case layout of
Inline -> case possibleHelpText of
Expand Down Expand Up @@ -342,6 +348,9 @@ textInput props = formSpecBuilderT do
, min: props'.min
, sizing: props'.sizing
, step: props'.step
, role: props'.role
, "aria-label": props'."aria-label"
, "aria-labelledby": props'."aria-labelledby"
}
)
props'.touched
Expand Down

0 comments on commit 046b2cc

Please sign in to comment.