threefoldtech / tfgrid-sdk-ts

Apache License 2.0
4 stars 8 forks source link

🐞 [Bug]: Edit zmachine validation #3335

Open zaelgohary opened 3 weeks ago

zaelgohary commented 3 weeks ago

Is there an existing issue for this?

which package/s did you face the problem with?

grid_client

What happened?

  it("should fail validation for entering invalid flist", () => {
    const emptyFlist = () => (zmachine.flist = "");
    const invalidURL = () => (zmachine.flist = "www.example.com");

    expect(emptyFlist).toThrow();
    expect(invalidURL).toThrow();
  });

  it("should fail validation for entering invalid entrypoint", () => {
    const invalidEntrypoint = () => (zmachine.entrypoint = undefined as any);

    expect(invalidEntrypoint).toThrow();
  });

  it("should fail validation for entering invalid size", () => {
    const maxSize = () => (zmachine.size = 10 * 1024 ** 5);
    const decimalSize = () => (zmachine.size = 1.2);
    const negativeSize = () => (zmachine.size = -1);

    expect(maxSize).toThrow();
    expect(decimalSize).toThrow();
    expect(negativeSize).toThrow();
  });

Both tests should pass but they fail as min & isurl validations are not added to size & flist.

Steps To Reproduce

run zmachine.test.ts script

which network/s did you face the problem on?

Dev

version

Locally

Twin ID/s

No response

Node ID/s

No response

Farm ID/s

No response

Contract ID/s

No response

Relevant screenshots/screen records

-

Relevant log output

yarn test zmachine.test.ts
yarn run v1.19.0
$ jest zmachine.test.ts
 FAIL  tests/modules/zmachine.test.ts
  Zmachine Class Tests
    ✓ should create a valid Zmachine instance (10 ms)
    ✓ should correctly serialize and deserialize a Zmachine instance (12 ms)
    ✓ should correctly handle env vars (4 ms)
    ✓ should correctly compute the challenge string (8 ms)
    ✓ should correctly handle the gpu array (4 ms)
    ✕ should fail validation for entering invalid flist (3 ms)
    ✓ should fail validation for entering invalid entrypoint (2 ms)
    ✕ should fail validation for entering invalid size (3 ms)
    ✓ should throw error if network public_ip is invalid (2 ms)
    ✓ should throw error if network interfaces values are invalid (4 ms)
    ✓ should throw an error if mount name is empty (3 ms)
    ✓ should fail if zmachine is parsed to an invalid object (3 ms)

  ● Zmachine Class Tests › should fail validation for entering invalid flist

    expect(received).toThrow()

    Received function did not throw

      94 |
      95 |     expect(emptyFlist).toThrow();
    > 96 |     expect(invalidURL).toThrow();
         |                        ^
      97 |   });
      98 |
      99 |   it("should fail validation for entering invalid entrypoint", () => {

      at Object.<anonymous> (tests/modules/zmachine.test.ts:96:24)

  ● Zmachine Class Tests › should fail validation for entering invalid size

    expect(received).toThrow()

    Received function did not throw

      110 |     expect(maxSize).toThrow();
      111 |     expect(decimalSize).toThrow();
    > 112 |     expect(negativeSize).toThrow();
          |                          ^
      113 |   });
      114 |
      115 |   it("should throw error if network public_ip is invalid", () => {

      at Object.<anonymous> (tests/modules/zmachine.test.ts:112:26)

Test Suites: 1 failed, 1 total
Tests:       2 failed, 10 passed, 12 total
Snapshots:   0 total
Time:        4.655 s, estimated 6 s
Ran all test suites matching /zmachine.test.ts/i.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
khaledyoussef24 commented 3 weeks ago

validation fixed and worked fine :

Image

already verified #2458