Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit 94d87bf

Browse files
committed
add interact with contract flow
1 parent b29ea26 commit 94d87bf

File tree

8 files changed

+349
-8
lines changed

8 files changed

+349
-8
lines changed

packages/nextjs/contracts/deployedContracts.ts

Lines changed: 260 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,265 @@
33
* You should not edit it manually or your changes might be overwritten.
44
*/
55

6-
const deployedContracts = {} as const;
6+
const deployedContracts = {
7+
devnet: {
8+
YourContract: {
9+
address:
10+
"0x6d94fef7ab42b1acb2683cdddbfc3fd17953d2d5d48576296c66dbe012d80c9",
11+
abi: [
12+
{
13+
type: "impl",
14+
name: "YourContractImpl",
15+
interface_name: "contracts::YourContract::IYourContract",
16+
},
17+
{
18+
type: "struct",
19+
name: "core::byte_array::ByteArray",
20+
members: [
21+
{
22+
name: "data",
23+
type: "core::array::Array::<core::bytes_31::bytes31>",
24+
},
25+
{
26+
name: "pending_word",
27+
type: "core::felt252",
28+
},
29+
{
30+
name: "pending_word_len",
31+
type: "core::integer::u32",
32+
},
33+
],
34+
},
35+
{
36+
type: "struct",
37+
name: "core::integer::u256",
38+
members: [
39+
{
40+
name: "low",
41+
type: "core::integer::u128",
42+
},
43+
{
44+
name: "high",
45+
type: "core::integer::u128",
46+
},
47+
],
48+
},
49+
{
50+
type: "enum",
51+
name: "core::bool",
52+
variants: [
53+
{
54+
name: "False",
55+
type: "()",
56+
},
57+
{
58+
name: "True",
59+
type: "()",
60+
},
61+
],
62+
},
63+
{
64+
type: "interface",
65+
name: "contracts::YourContract::IYourContract",
66+
items: [
67+
{
68+
type: "function",
69+
name: "greeting",
70+
inputs: [],
71+
outputs: [
72+
{
73+
type: "core::byte_array::ByteArray",
74+
},
75+
],
76+
state_mutability: "view",
77+
},
78+
{
79+
type: "function",
80+
name: "set_greeting",
81+
inputs: [
82+
{
83+
name: "new_greeting",
84+
type: "core::byte_array::ByteArray",
85+
},
86+
{
87+
name: "amount_eth",
88+
type: "core::integer::u256",
89+
},
90+
],
91+
outputs: [],
92+
state_mutability: "external",
93+
},
94+
{
95+
type: "function",
96+
name: "withdraw",
97+
inputs: [],
98+
outputs: [],
99+
state_mutability: "external",
100+
},
101+
{
102+
type: "function",
103+
name: "premium",
104+
inputs: [],
105+
outputs: [
106+
{
107+
type: "core::bool",
108+
},
109+
],
110+
state_mutability: "view",
111+
},
112+
],
113+
},
114+
{
115+
type: "impl",
116+
name: "OwnableImpl",
117+
interface_name: "openzeppelin_access::ownable::interface::IOwnable",
118+
},
119+
{
120+
type: "interface",
121+
name: "openzeppelin_access::ownable::interface::IOwnable",
122+
items: [
123+
{
124+
type: "function",
125+
name: "owner",
126+
inputs: [],
127+
outputs: [
128+
{
129+
type: "core::starknet::contract_address::ContractAddress",
130+
},
131+
],
132+
state_mutability: "view",
133+
},
134+
{
135+
type: "function",
136+
name: "transfer_ownership",
137+
inputs: [
138+
{
139+
name: "new_owner",
140+
type: "core::starknet::contract_address::ContractAddress",
141+
},
142+
],
143+
outputs: [],
144+
state_mutability: "external",
145+
},
146+
{
147+
type: "function",
148+
name: "renounce_ownership",
149+
inputs: [],
150+
outputs: [],
151+
state_mutability: "external",
152+
},
153+
],
154+
},
155+
{
156+
type: "constructor",
157+
name: "constructor",
158+
inputs: [
159+
{
160+
name: "owner",
161+
type: "core::starknet::contract_address::ContractAddress",
162+
},
163+
],
164+
},
165+
{
166+
type: "event",
167+
name: "openzeppelin_access::ownable::ownable::OwnableComponent::OwnershipTransferred",
168+
kind: "struct",
169+
members: [
170+
{
171+
name: "previous_owner",
172+
type: "core::starknet::contract_address::ContractAddress",
173+
kind: "key",
174+
},
175+
{
176+
name: "new_owner",
177+
type: "core::starknet::contract_address::ContractAddress",
178+
kind: "key",
179+
},
180+
],
181+
},
182+
{
183+
type: "event",
184+
name: "openzeppelin_access::ownable::ownable::OwnableComponent::OwnershipTransferStarted",
185+
kind: "struct",
186+
members: [
187+
{
188+
name: "previous_owner",
189+
type: "core::starknet::contract_address::ContractAddress",
190+
kind: "key",
191+
},
192+
{
193+
name: "new_owner",
194+
type: "core::starknet::contract_address::ContractAddress",
195+
kind: "key",
196+
},
197+
],
198+
},
199+
{
200+
type: "event",
201+
name: "openzeppelin_access::ownable::ownable::OwnableComponent::Event",
202+
kind: "enum",
203+
variants: [
204+
{
205+
name: "OwnershipTransferred",
206+
type: "openzeppelin_access::ownable::ownable::OwnableComponent::OwnershipTransferred",
207+
kind: "nested",
208+
},
209+
{
210+
name: "OwnershipTransferStarted",
211+
type: "openzeppelin_access::ownable::ownable::OwnableComponent::OwnershipTransferStarted",
212+
kind: "nested",
213+
},
214+
],
215+
},
216+
{
217+
type: "event",
218+
name: "contracts::YourContract::YourContract::GreetingChanged",
219+
kind: "struct",
220+
members: [
221+
{
222+
name: "greeting_setter",
223+
type: "core::starknet::contract_address::ContractAddress",
224+
kind: "key",
225+
},
226+
{
227+
name: "new_greeting",
228+
type: "core::byte_array::ByteArray",
229+
kind: "key",
230+
},
231+
{
232+
name: "premium",
233+
type: "core::bool",
234+
kind: "data",
235+
},
236+
{
237+
name: "value",
238+
type: "core::integer::u256",
239+
kind: "data",
240+
},
241+
],
242+
},
243+
{
244+
type: "event",
245+
name: "contracts::YourContract::YourContract::Event",
246+
kind: "enum",
247+
variants: [
248+
{
249+
name: "OwnableEvent",
250+
type: "openzeppelin_access::ownable::ownable::OwnableComponent::Event",
251+
kind: "flat",
252+
},
253+
{
254+
name: "GreetingChanged",
255+
type: "contracts::YourContract::YourContract::GreetingChanged",
256+
kind: "nested",
257+
},
258+
],
259+
},
260+
],
261+
classHash:
262+
"0x4e881db1286914119f2c900d19ab8fea1811614fdfa86d5f7539f7bc1c83e9c",
263+
},
264+
},
265+
} as const;
7266

8267
export default deployedContracts;

packages/snfoundry/contracts/Scarb.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ checksum = "sha256:44f32d242af1e43982decc49c563e613a9b67ade552f5c3d5cde504e92f74
5656

5757
[[package]]
5858
name = "snforge_scarb_plugin"
59-
version = "0.34.0"
59+
version = "0.35.1"
6060
source = "registry+https://scarbs.xyz/"
61-
checksum = "sha256:56f2b06ff2f0d8bbdfb7fb6c211fba7e4da6e5334ea70ba849af329a739faf11"
61+
checksum = "sha256:1b6d50abc7f306a06abf90649bcd60a3bc1cdf6d0dc21a9725c71b014a334bab"
6262

6363
[[package]]
6464
name = "snforge_std"
65-
version = "0.34.0"
65+
version = "0.35.1"
6666
source = "registry+https://scarbs.xyz/"
67-
checksum = "sha256:bd20964bde07e6fd0f7adb50d41216f05d66abd422ed82241030369333385876"
67+
checksum = "sha256:e25cbeb9cbed6da8e14ab19ad0e7c1d888055dfee62978a845ce669cfaba5d93"
6868
dependencies = [
6969
"snforge_scarb_plugin",
7070
]

ui-automation/tests/debug.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import endpoint from "./configTypes";
2+
import { test, expect } from "@playwright/test";
3+
import { navigateAndWait } from "./utils/navigate";
4+
import { HomePage } from "./pages/HomePage";
5+
import { DebugPage } from "./pages/DebugPage";
6+
7+
test("interact with contract", async ({ page }) => {
8+
await navigateAndWait(page, endpoint.BASE_URL);
9+
const homePage = new HomePage(page);
10+
await homePage.getDebugPageLinkButton().click();
11+
12+
await expect(page.getByText("YourContract")).toBeVisible();
13+
14+
const debugPage = new DebugPage(page);
15+
await debugPage.connectWallet("0x64b4...5691");
16+
17+
const writeTab = await debugPage.getWriteTab();
18+
await writeTab.click();
19+
20+
const withdrawSection = page.locator("div.py-5", {
21+
has: page.locator("p.text-function", { hasText: "withdraw" }),
22+
});
23+
const sendButton = withdrawSection.locator("button", { hasText: "Send 💸" });
24+
await sendButton.click();
25+
26+
const transactionReceipt = withdrawSection.locator("strong", {
27+
hasText: "Transaction Receipt",
28+
});
29+
await expect(transactionReceipt).toBeVisible();
30+
});

ui-automation/tests/home.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import endpoint from "./configTypes";
22
import { test, expect } from "@playwright/test";
3-
import { HomePage } from "./HomePage";
3+
import { HomePage } from "./pages/HomePage";
44

55
test("Expect to connect to devnet with Burner Wallet", async ({ page }) => {
66
// Go to the Droplets product page of DigitalOcean web page

ui-automation/tests/HomePage.ts renamed to ui-automation/tests/pages/BasePage.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Page } from "playwright";
22

3-
export class HomePage {
4-
private page: Page;
3+
export class BasePage {
4+
protected page: Page;
55
constructor(page: Page) {
66
this.page = page;
77
}
@@ -19,4 +19,16 @@ export class HomePage {
1919
getAccountButton(account: string) {
2020
return this.page.locator(`button:has-text("${account}")`);
2121
}
22+
23+
async connectWallet(account: string) {
24+
const connectButton = await this.getConnectButton();
25+
await connectButton.click();
26+
27+
await this.getConnecterButton("Burner Wallet").click();
28+
29+
const button = this.getAccountButton(account);
30+
await button.scrollIntoViewIfNeeded();
31+
await this.page.waitForTimeout(500);
32+
await button.click({ force: true, timeout: 5000 });
33+
}
2234
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Page } from "playwright";
2+
import { BasePage } from "./BasePage";
3+
4+
export class DebugPage extends BasePage {
5+
constructor(page: Page) {
6+
super(page);
7+
}
8+
9+
getWriteTab() {
10+
return this.page
11+
.locator('div:not([class*="hidden"]) .tabs a.tab', {
12+
hasText: "Write",
13+
})
14+
.first();
15+
}
16+
}

ui-automation/tests/pages/HomePage.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Page } from "playwright";
2+
import { BasePage } from "./BasePage";
3+
4+
export class HomePage extends BasePage {
5+
constructor(page: Page) {
6+
super(page);
7+
}
8+
9+
getDebugPageLinkButton() {
10+
return this.page.locator("a", {
11+
hasText: "Debug Contracts",
12+
has: this.page.locator("svg"),
13+
});
14+
}
15+
}

ui-automation/tests/utils/navigate.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Page } from "@playwright/test";
2+
3+
export async function navigateAndWait(page: Page, url: string) {
4+
await page.goto(url);
5+
await Promise.all([
6+
page.waitForLoadState("domcontentloaded"),
7+
page.waitForLoadState("networkidle"),
8+
]);
9+
}

0 commit comments

Comments
 (0)