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

Plt 8561/automate two users #23

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions e2e/artifacts/lace-mnemonic.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
donor afford margin car sunset tool mountain fringe question fuel obtain hedgehog mouse use bitter repeat judge street human voice execute soldier reunion youth
3 changes: 3 additions & 0 deletions e2e/config/mappings/page-elements/contract-simulation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Currency Amount" : { "role": "spinbutton", "name": "Decimal Amount"}
}
2 changes: 1 addition & 1 deletion e2e/config/mappings/page-elements/home.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"contract-input": {"role": "textbox", "name": "contract-input" },
"choice-input": {"role": "spinbutton", "name": "choice-input" }
}
}
3 changes: 3 additions & 0 deletions e2e/config/mappings/page-elements/javascript-editor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"JS Editor": { "role": "textbox", "name": "Editor content;Press Alt+F1 for Accessibility Options."}
}
7 changes: 7 additions & 0 deletions e2e/config/mappings/page-elements/playground.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"editor header": { "role": "heading", "name": "project-title"},
"playground editor": { "role": "heading", "name": "javascript-editor"},
"Compile": { "role": "button", "name": "Compile"},
"Send To Simulator": { "role": "button", "name": "Send to Simulator"},
"JS Editor": { "role": "textbox", "name": "Editor content;Press Alt+F1 for Accessibility Options."}
}
3,226 changes: 3,151 additions & 75 deletions e2e/package-lock.json

Large diffs are not rendered by default.

51 changes: 50 additions & 1 deletion e2e/src/features/apply-inputs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ Feature: As a user, I would like to apply an input on a current contract
| lace |
| nami |

@dev
Scenario Outline: Creating a notify contract with a <wallet_name> wallet
Given I configure my <wallet_name> wallet
Given I am on the "home" page
Expand Down Expand Up @@ -128,3 +127,53 @@ Feature: As a user, I would like to apply an input on a current contract
| lace |
| nami |

@dev
Scenario: Creating an escrow contract with two separate wallets
Given I configure my lace wallet
Given I configure my nami wallet
Given I am on the "home" page
Then I should see a "heading" with "Choose a wallet" text

When I authorize my lace wallet
Given I am on the "home" page
When I authorize my nami wallet
Then I should see a "button" with "Create a contract" text

When I click the "button" with "Create a contract" text
And I generate the contract "Escrow" and write it to "/tmp/escrow.json"
And I enter the contents of "/tmp/escrow.json" into the "contract-input" field

When I click the "button" with "Submit contract" text And sign the transaction with nami wallet
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 "Make deposit" text

When I click the "checkbox" with "Deposit 10 ₳" text
And I click the "button" with "Make deposit" text And sign the transaction with nami wallet
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

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

When I select "Report problem" from the "form-select" dropdown
And I fill in the "choice-input" input with "1"
And I click the "button" with "Advance contract" text And sign the transaction with nami wallet
Then I should see the first "button" showing "Syncing" text

Given I am on the "home" page
When I authorize my lace wallet
And I should see the first "button" showing "Advance" text

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

When I select "Confirm problem" from the "form-select" dropdown
And I fill in the "choice-input" input with "1"
And I click the "button" with "Advance contract" text And sign the transaction with lace wallet

And I pause the page
20 changes: 20 additions & 0 deletions e2e/src/step-definitions/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,23 @@ When('I enter the contents of {string} into the {string} field',
}
});
});

When('I select {string} from the {string} dropdown',
async function (this: ScenarioWorld, option: string, name: string) {
const {
screen: { page },
globalConfig,
globalStateManager
} = this;

await waitFor(async() => {
const locator = await page.locator(`select.${name}`);
const result = await locator.isVisible();

if (result) {
await locator.selectOption(option);
return result;
}
});
}
)
184 changes: 182 additions & 2 deletions e2e/src/step-definitions/generate-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,182 @@ import {
} from "@marlowe.io/language-core-v1";
import { MarloweJSON } from "@marlowe.io/adapter/codec";

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

const mkEscrow = (buyerAddress: string, sellerAddress: string): Contract => {
const twentyMinutesInMilliseconds = 20 * 60 * 1000;
const inTwentyMinutes = datetoTimeout(new Date(Date.now() + twentyMinutesInMilliseconds));

return {
timeout: inTwentyMinutes,
timeout_continuation: "close",
when: [
{
then: {
when: [
{
then: "close",
case: {
for_choice: {
choice_owner: {
address: buyerAddress
},
choice_name: "Everything is alright"
},
choose_between: [
{
to: 0n,
from: 0n
}
]
}
},
{
then: {
token: {
token_name: "",
currency_symbol: ""
},
to: {
account: {
address: buyerAddress
}
},
then: {
when: [
{
then: "close",
case: {
for_choice: {
choice_owner: {
address: sellerAddress
},
choice_name: "Confirm problem"
},
choose_between: [
{
to: 1n,
from: 1n
}
]
}
},
{
then: {
when: [
{
then: {
token: {
token_name: "",
currency_symbol: ""
},
to: {
party: {
address: sellerAddress
}
},
then: "close",
pay: 10000000n,
from_account: {
address: buyerAddress
}
},
case: {
for_choice: {
choice_owner: {
address: sellerAddress
},
choice_name: "Dismiss claim"
},
choose_between: [
{
to: 0n,
from: 0n
}
]
}
},
{
then: "close",
case: {
for_choice: {
choice_owner: {
address: sellerAddress
},
choice_name: "Confirm problem"
},
choose_between: [
{
to: 1n,
from: 1n
}
]
}
}
],
timeout_continuation: "close",
timeout: inTwentyMinutes
},
case: {
for_choice: {
choice_owner: {
address: sellerAddress
},
choice_name: "Dispute problem"
},
choose_between: [
{
to: 0n,
from: 0n
}
]
}
}
],
timeout_continuation: "close",
timeout: inTwentyMinutes
},
pay: 10000000n,
from_account: {
address: sellerAddress
}
},
case: {
for_choice: {
choice_owner: {
address: buyerAddress
},
choice_name: "Report problem"
},
choose_between: [
{
to: 1n,
from: 1n
}
]
}
}
],
timeout_continuation: "close",
timeout: inTwentyMinutes
},
case: {
party: {
address: buyerAddress
},
of_token: {
token_name: "",
currency_symbol: ""
},
into_account: {
address: sellerAddress
},
deposits: 10000000n
}
}
],
}
}

const mkSimpleDeposit = (address: string): Contract => {
const twentyMinutesInMilliseconds = 20 * 60 * 1000;
Expand Down Expand Up @@ -98,7 +273,7 @@ When(
const {
globalStateManager
} = this;
const walletAddress = globalStateManager.getValue("wallet-address");
const walletAddress = globalStateManager.popValue("wallet-address");
switch (contractName) {
case "SimpleDeposit":
const contract1 = mkSimpleDeposit(walletAddress);
Expand All @@ -116,6 +291,11 @@ When(
const contract4 = mkSimpleNotify(walletAddress);
globalStateManager.appendValue(fileName, MarloweJSON.stringify(contract4, null, 4))
break;
case "Escrow":
const walletAddress2 = globalStateManager.getValue("wallet-address");
const contract5 = mkEscrow(walletAddress, walletAddress2);
globalStateManager.appendValue(fileName, MarloweJSON.stringify(contract5, null, 4))
break;
}
}
);
2 changes: 1 addition & 1 deletion e2e/src/step-definitions/wallet-config/laceWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ When(

const EXTENSION_URL = 'chrome-extension://gafhhkghbfjjkeiendhlofajokpaflmk';

const mnemonic = fs.readFileSync('artifacts/mnemonic.txt', 'utf-8');
const mnemonic = fs.readFileSync('artifacts/lace-mnemonic.txt', 'utf-8');
const words = mnemonic.trim().split(' ');
const newPage = await page.context().newPage();
await newPage.goto(`${EXTENSION_URL}/app.html`);
Expand Down
Loading
Loading