Skip to content

Commit

Permalink
Merge pull request TaggrNetwork#37 from TaggrNetwork/refactoring
Browse files Browse the repository at this point in the history
Refactoring of proposal creations
  • Loading branch information
taggrx authored Mar 24, 2024
2 parents 78456f0 + 42df836 commit 2a560e4
Show file tree
Hide file tree
Showing 15 changed files with 542 additions and 539 deletions.
9 changes: 5 additions & 4 deletions e2e/test1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test.describe("Upgrades & token transfer flow", () => {
// Create a post
await page.getByRole("button", { name: "POST" }).click();
await page.locator("textarea").fill("Message from Eve");
await page.getByRole("button", { name: "SEND" }).click();
await page.getByRole("button", { name: "SUBMIT" }).click();
await page.waitForURL(/#\/post\//);

// Create an invite
Expand Down Expand Up @@ -199,9 +199,7 @@ test.describe("Upgrades & token transfer flow", () => {
page.getByRole("heading", { name: "PROPOSALS" }),
).toBeVisible();
await page.getByTestId("proposals-burger-button").click();
await page.getByRole("button", { name: "RELEASE" }).click();
await page.locator("textarea").fill("A regular upgrade");
await page.locator("input[type=text]").fill("coffeecoffeecoffee");

// Upload the binary
const binaryPath = resolve(
Expand All @@ -215,11 +213,14 @@ test.describe("Upgrades & token transfer flow", () => {

const [fileChooser] = await Promise.all([
page.waitForEvent("filechooser"),
page.locator('input[type="file"]').click(),
page.getByTestId("bin-file-picker").click(),
]);

const buildHash = await hashFile(binaryPath);
await fileChooser.setFiles([binaryPath]);
// Wait for async proposal validation
await page.waitForTimeout(2000);
await page.locator("input[type=text]").fill("coffeecoffeecoffee");
await page.getByRole("button", { name: "SUBMIT" }).click();
await expect(page.getByText(/STATUS.*OPEN/)).toBeVisible();
await expect(page.getByText("TYPE: RELEASE")).toBeVisible();
Expand Down
8 changes: 4 additions & 4 deletions e2e/test2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ test.describe("Regular users flow", () => {
page.getByTestId("file-picker").click(),
]);
await fileChooser.setFiles([imagePath]);
await page.getByRole("button", { name: "SEND" }).click();
await page.getByRole("button", { name: "SUBMIT" }).click();
await page.waitForURL(/#\/post\//);

// Make sure the post loads
Expand All @@ -102,7 +102,7 @@ test.describe("Regular users flow", () => {
await page
.locator("textarea")
.fill(value + "\n\n**Edit:** this is a post-scriptum");
await page.getByRole("button", { name: "SEND" }).click();
await page.getByRole("button", { name: "SUBMIT" }).click();
await page.waitForURL(/#\/post\//);
await expect(page.getByText("post-scriptum")).toBeVisible();

Expand Down Expand Up @@ -192,7 +192,7 @@ test.describe("Regular users flow", () => {
// Now we can create a new post in the new realm
await page.getByRole("button", { name: "POST" }).click();
await page.locator("#form_undefined_3").fill("Hello from Alice!");
await page.getByRole("button", { name: "SEND" }).click();
await page.getByRole("button", { name: "SUBMIT" }).click();

// Make sure the post is visible on the front page and is labeled with realm tag
await page.locator("#logo").click();
Expand Down Expand Up @@ -245,7 +245,7 @@ test.describe("Regular users flow", () => {
.click();
await page.getByPlaceholder("Reply here...").focus();
await page.locator("textarea").fill("Bob was here");
await page.getByRole("button", { name: "SEND" }).click();
await page.getByRole("button", { name: "SUBMIT" }).click();

// Wait because the UI waits for 4s before sending the command
await page.waitForTimeout(4000);
Expand Down
4 changes: 2 additions & 2 deletions e2e/test3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test.describe("Regular users flow, part two", () => {
await page.locator("textarea").fill("Poll from John");
await page.getByTestId("poll-button").click();
await page.getByTestId("poll-editor").fill("YES\nNO\nCOMMENTS");
await page.getByRole("button", { name: "SEND" }).click();
await page.getByRole("button", { name: "SUBMIT" }).click();
await page.waitForURL(/#\/post\//);

// Make sure the post loads
Expand Down Expand Up @@ -85,7 +85,7 @@ test.describe("Regular users flow, part two", () => {
await feedItem.locator("button[title=Repost]").click();
await page.waitForURL(/#\/new/);
await page.locator("textarea").fill("Repost of the poll");
await page.getByRole("button", { name: "SEND" }).click();
await page.getByRole("button", { name: "SUBMIT" }).click();
await page.waitForURL(/#\/post\//);

// Make sure the post is visible on the front page too
Expand Down
4 changes: 2 additions & 2 deletions e2e/test4.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ test.describe("Report and transfer to user", () => {
await page.locator("#logo").click();
await page.getByRole("button", { name: "POST" }).click();
await page.locator("textarea").fill("Good stuff");
await page.getByRole("button", { name: "SEND" }).click();
await page.getByRole("button", { name: "SUBMIT" }).click();
await page.waitForURL(/#\/post\//);
});

Expand All @@ -78,7 +78,7 @@ test.describe("Report and transfer to user", () => {
await page.locator("#logo").click();
await page.getByRole("button", { name: "POST" }).click();
await page.locator("textarea").fill("Illigal stuff");
await page.getByRole("button", { name: "SEND" }).click();
await page.getByRole("button", { name: "SUBMIT" }).click();
await page.waitForURL(/#\/post\//);
});

Expand Down
33 changes: 1 addition & 32 deletions src/backend/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2828,25 +2828,6 @@ fn covered_by_feeds(
None
}

pub fn parse_amount(amount: &str, token_decimals: u8) -> Result<u64, String> {
let parse = |s: &str| {
s.parse::<u64>()
.map_err(|err| format!("couldn't parse as u64: {:?}", err))
};
match &amount.split('.').collect::<Vec<_>>().as_slice() {
[tokens] => Ok(parse(tokens)? * 10_u64.pow(token_decimals as u32)),
[tokens, after_comma] => {
let mut after_comma = after_comma.to_string();
while after_comma.len() < token_decimals as usize {
after_comma.push('0');
}
let after_comma = &after_comma[..token_decimals as usize];
Ok(parse(tokens)? * 10_u64.pow(token_decimals as u32) + parse(after_comma)?)
}
_ => Err(format!("can't parse amount {}", amount)),
}
}

pub fn display_tokens(amount: u64, decimals: u32) -> String {
let base = 10_u64.pow(decimals);
if decimals == 8 {
Expand Down Expand Up @@ -2980,18 +2961,6 @@ pub(crate) mod tests {
assert_eq!(display_tokens(34544, 2), "345.44");
}

#[test]
fn test_amount_parsing() {
assert_eq!(parse_amount("12.34", 8), Ok(1234000000));
assert_eq!(parse_amount("0.0034", 8), Ok(340000));
assert_eq!(parse_amount("00.67", 2), Ok(67));
assert_eq!(parse_amount("1.25", 2), Ok(125));
assert_eq!(parse_amount("123.4567", 2), Ok(12345));
assert_eq!(parse_amount("777", 2), Ok(77700));
assert_eq!(parse_amount("0777", 2), Ok(77700));
assert!(parse_amount("34,56", 2).is_err());
}

#[test]
fn test_donated_rewards() {
STATE.with(|cell| {
Expand Down Expand Up @@ -3389,7 +3358,7 @@ pub(crate) mod tests {
let user = state.principal_to_user_mut(pr(1)).unwrap();
user.stalwart = true;
let user_id = user.id;
let proposal_id = proposals::propose(
let proposal_id = proposals::tests::propose(
state,
pr(1),
"test".into(),
Expand Down
Loading

0 comments on commit 2a560e4

Please sign in to comment.