Magickbase / neuron-public-issues

Neuron Issues
4 stars 3 forks source link

Support automated tests for full-node mode and light-client mode #290

Open Keith-CY opened 9 months ago

Keith-CY commented 9 months ago

Recently we found some unexpected behaviors of Neuron when it was in the light client mode. Then I realized that Neuron is a very special case in CKB ecosystem because it's the only product that supports full-node and light-client simultaneously. That means, tests should be doubled for the same function.

Due to the increment in workload, we should accelerate the automation of tests.

It would be challenging because we haven't figured out how to run the e2e tests with full-node in the github runner but now there comes another ckb client.

I'll connect to acceptance team to see if they have handled such situations.

Ref:

Keith-CY commented 8 months ago

IMO, Neuron's E2E testing can be divided into two categories:

  1. UI interaction testing, involving link navigation, form input, and data display.
  2. Testing the synchronization of on-chain data, ensuring that data remains consistent and complete for a given wallet when synchronized to a specific height.

The first category of testing is similar to standard software testing processes and can be supported by automating verification by importing test data into Neuron's database. The specific workflow is as follows:

  1. Trigger automated testing upon code submission.
  2. Before running the tests, repackage Neuron.
  3. Before running Neuron, replace its built-in database with a test database, or use a script to write data into Neuron. Using a script is recommended, as it allows for adapting to data format changes, such as adding or removing fields.
  4. Run Neuron and use testing tools to verify the interaction of the pages.

The second category of testing is different from standard software testing and is more similar to end-to-end testing for backend services. One challenging aspect is the need to cover both full node and light client modes. However, after isolating the full node and light client databases (https://github.com/Magickbase/neuron-public-issues/issues/294), it is possible to complete this testing by comparing database snapshots. The specific steps are as follows:

  1. Select a wallet with complete test data and export databases for both the full node and the light client, synchronized to the same height, as the testing baseline.
  2. Build a persistent testing environment to provide external nodes and light clients.
  3. Before running the tests, repackage Neuron.
  4. Run Neuron and wait for it to synchronize to the specified height.
  5. Use a script to compare Neuron's database with the baseline database.

Since the data volume for light clients is smaller, testing the synchronization of light clients can also be performed by importing them into the testing environment each time, rather than maintaining a persistent environment.

silySuper commented 8 months ago

In order to ensure the continuity of dynamic operations,we should consider how to make data usable.For example,if we want to test send transaction firstly ,then send lock time transaction,sufficient balance in wallet is needed to advoid throw abnormal tips and automated situation are interrupted.

Keith-CY commented 7 months ago

Now that E2E tests are grouped into 3 parts, we can make schedules for each one.

I'm a bit familiar with test frameworks for UI/interactions, so I will lead this part.

There are 2 frameworks for an electron app

They are almost the same for our project except

  1. cypress is somehow heavy because it relies on a local app(CI would fail because it cannot download the app, really bothering);
  2. playwright is so fresh that its support for electron is experimental.

Personally prefer playwright for our test framework of UI because failure to download cypress in CI did annoy me, any idea from @yanguoyu @homura @WhiteMinds @devchenyan @zhangyouxin @Daryl-L @PainterPuppets

Keith-CY commented 7 months ago

Now that E2E tests are grouped into 3 parts, we can make schedules for each one.

I'm a bit familiar with test frameworks for UI/interactions, so I will lead this part.

There are 2 frameworks for an electron app

They are almost the same for our project except

  1. cypress is somehow heavy because it relies on a local app(CI would fail because it cannot download the app, really bothering);

  2. playwright is so fresh that its support for electron is experimental.

Personally prefer playwright for our test framework of UI because failure to download cypress in CI did annoy me, any idea from @yanguoyu @homura @WhiteMinds @devchenyan @zhangyouxin @Daryl-L @PainterPuppets

Playwright will be used if there's no more feedback

Danie0918 commented 5 months ago

@Keith-CY This issue will be taken by @devchenyan, please hand over the relevant work content.

Keith-CY commented 5 months ago

@Keith-CY This issue will be taken by @devchenyan, please hand over the relevant work content.

I'll DM @devchenyan for this task

silySuper commented 2 months ago

Which github code link is related to this ?

Keith-CY commented 2 months ago

Which github code link is related to this ?

The PR is https://github.com/nervosnetwork/neuron/pull/3004 but I found the CI failed, please have a check @devchenyan

Keith-CY commented 2 months ago

Which github code link is related to this ?

The PR is nervosnetwork/neuron#3004 but I found the CI failed, please have a check @devchenyan

Any update on this PR @devchenyan

silySuper commented 2 months ago

Now neuron can launch ,but can not locate element,what is the way to locate electron element ?@devchenyan

silySuper commented 2 months ago

If launch by manual operation,we can write send transaction as first example ,does send page element can be located?can you upload a video for writen process if it is convenient for you ? @devchenyan

Danie0918 commented 1 month ago

Any update on this PR @devchenyan @silySuper

silySuper commented 1 month ago

Already know how to location element, main examples is writing.

silySuper commented 1 month ago

network can not connected by playwritetest,always show is connecting either innernal node or light client node

截屏2024-05-08 16 55 03

main.log

@devchenyan

silySuper commented 1 month ago

Now is solving in full node yarn start can sync normally,but test:e2e can not sync.

silySuper commented 1 month ago

1.test environment sync is OK now 2.main test case(full node and light client node): (page)

截屏2024-06-17 10 38 55

a.send transaction--done b.check history transation --done c.nervos dao deposit --done d.one cell consume--done e.create account in asset accounts--done f.amend transaction--done g.claim in customized page-done (menu)

截屏2024-06-17 10 38 17

h.sign message--to do i.multisig message --to do j.offline message--to do k.broadcast message--to do (hard wallet) l:receive m:send

@Danie0918 progress is updated here.

Keith-CY commented 1 month ago

1.test environment sync is OK now 2.main test case: a.send transaction--done b.check history transation --done c.nervos dao deposit -- is doing d.two cells consume--to do e.create account in asset accounts--to do f.amend transaction--to do(full node) g.claim in customized page--to do (window) h.sign message--to do i.multisig message --to do j.offline message--to do k.broadcast message--to do

3.I have no permission to push code to enable-playwrite branch,please open it. @Keith-CY

Permission updated

silySuper commented 1 month ago

Performance test situations to do: 1.A single transaction has a large number of cells. 2.Extra large transactions. 3.A single wallet has a large number of addresses. 4.A large number of wallets.

silySuper commented 2 weeks ago

1.svg element is hard to locate.It will be more convenient to write locator if it is img.I look other some websites svg locate,they does not use svg,but use like this: await page.locator('footer').filter({ hasText: '长沙红胖子Qt 2024-06-14 10:09 0 0' }).getByRole('link').nth(1).click();maybe it need to write detailed hierarchical relationships 2.some elements can only be located by xpath,it need to be modified if the page has little change,and may increase maintain cost,can you add id to each elemment if it is convenient for you? @devchenyan @yanguoyu

yanguoyu commented 2 weeks ago

1.svg element is hard to locate.It will be more convenient to write locator if it is img.I look other some websites svg locate,they does not use svg,but use like this: await page.locator('footer').filter({ hasText: '长沙红胖子Qt 2024-06-14 10:09 0 0' }).getByRole('link').nth(1).click();maybe it need to write detailed hierarchical relationships

Why does the SVG is hard to locate? I don't know the difference between locating svg and img.

2.some elements can only be located by xpath,it need to be modified if the page has little change,and may increase maintain cost,can you add id to each elemment if it is convenient for you?

Adding an ID for each element is hard to maintain because the ID should not be the same on the global page. How about adding an ID for the page root or component root? Anyway, e2e tests do need to be modified when the page changes.

silySuper commented 2 weeks ago

1.I have not seen anything about svg in playwrite official website yet,so I search other websites and only find https://www.cnblogs.com/yoyoketang/p/17354636.html,which does not written integrally.But I have solve how to locate svg by random attempt. 2.increase change is needed,but other change less and less.

yanguoyu commented 2 weeks ago

1.I have not seen anything about svg in playwrite official website yet,so I search other websites and only find https://www.cnblogs.com/yoyoketang/p/17354636.html,which does not written integrally.But I have solve how to locate svg by random attempt.

I guess use selector to locate the SVG is also ok? Or use https://playwright.dev/docs/api/class-page#page-query-selector? eg: await page.locator('svg').click();

2.increase change is needed,but other change less and less.

Add ID for each element is a bit wired even if it's just for testing. What do you think? @Keith-CY

silySuper commented 2 weeks ago

1.I have not seen anything about svg in playwrite official website yet,so I search other websites and only find https://www.cnblogs.com/yoyoketang/p/17354636.html,which does not written integrally.But I have solve how to locate svg by random attempt.

I guess use selector to locate the SVG is also ok? Or use https://playwright.dev/docs/api/class-page#page-query-selector? eg: await page.locator('svg').click();

2.increase change is needed,but other change less and less.

Add ID for each element is a bit wired even if it's just for testing. What do you think? @Keith-CY

1.await page.locator('svg').click();not use ,svg need to locate detailed svg.because several svg is in one page,I have solved by name() and xpath

yanguoyu commented 2 weeks ago

1.I have not seen anything about svg in playwrite official website yet,so I search other websites and only find https://www.cnblogs.com/yoyoketang/p/17354636.html,which does not written integrally.But I have solve how to locate svg by random attempt.

I guess use selector to locate the SVG is also ok? Or use https://playwright.dev/docs/api/class-page#page-query-selector? eg: await page.locator('svg').click();

2.increase change is needed,but other change less and less.

Add ID for each element is a bit wired even if it's just for testing. What do you think? @Keith-CY

1.await page.locator('svg').click();not use ,svg need to locate detailed svg.because several svg is in one page,I have solved by name() and xpath

The locator function can be called by the locator result. How about use page.locator('path').locator(svg)?

silySuper commented 2 weeks ago

1.test environment sync is OK now 2.main test case(full node and light client node): (page) 截屏2024-06-17 10 38 55

a.send transaction--done b.check history transation --done c.nervos dao deposit --done d.one cell consume--done e.create account in asset accounts--done f.amend transaction--done g.claim in customized page-done (menu) 截屏2024-06-17 10 38 17

h.sign message--to do i.multisig message --to do j.offline message--to do k.broadcast message--to do (hard wallet) l:receive m:send

@Danie0918 progress is updated here.

For menu function automation,palywrite can not operated,but can use AppleScript.Now this script can run in my local neuron:

Image

but can not run in app launched by playwrite becauseof this:

Image

can this appname Electron changed to Neuron in playwrite? @devchenyan @yanguoyu

silySuper commented 1 week ago

updated

(menu-tool) click menu by AppleScript because playwrite does not support Operating system automation h.sign message--done i.multisig message --is doing(Key point:address must be different and effective every time) j.offline message--to do(Key point:json document in local must be different and effective every time) k.broadcast message--to do (menu-hard wallet) l:create --done m:receive--done n:send--done (enhancement) o:optimize code layering--to do

silySuper commented 5 days ago

updated

(menu-tool) i.multisig message--done j.offline message--done k.broadcast message--done (enhancement) o:optimize code layering and run all--is doing(plan to finish before date 2024.7.5 ) (add new case) p.export transaction--done q.sign and export transaction--done @Danie0918 @Keith-CY

silySuper commented 1 day ago

Applescript can not find process Neuron now(which can run last week),I have searched running process,does not have process name Neuron.But When I replace Electron ,it shows menubar which is not belong to Neuron.

Image

silySuper commented 9 hours ago

Testnet network can not sync ,and shows is connecting after refresh several times.

Image

Image

main.log

bundled-ckb.log

bundled-ckb.log

please have a look~

@devchenyan @yanguoyu

yanguoyu commented 8 hours ago

Testnet network can not sync ,and shows is connecting after refresh several times.

Image

Image

main.log

bundled-ckb.log

bundled-ckb.log

please have a look~

@devchenyan @yanguoyu

From the main.log you connect to the local ckb node. So may be the bundled-ckb.log should be your local ckb node log but not export from the Neuron.

CKB:    fail to start bundled CKB with error:
[2024-07-03T08:59:42.080Z] [error] Error: ENOENT: no such file or directory, copyfile 'neuron/packages/neuron-wallet/light/ckb_light_testnet.toml' -> '/Users/chllp/Library/Application Support/Electron/chains/light/testnet/ckb_light.toml'

And from the log, neuron start light client failed, it show that you start with development. So you'd better run ./scripts/download-ckb.sh to download the light client binary file.