L2-Technology / sensei

A lightning node implementation for everyone
https://l2.technology/sensei
Other
199 stars 39 forks source link

Integration tests (and a little more) #75

Closed johncantrell97 closed 2 years ago

johncantrell97 commented 2 years ago

This PR introduces a small refactor, a major bugfix, and a way to write integration tests for Sensei with a comprehensive example.

async fn smoke_test(bitcoind: BitcoinD, admin_service: AdminService) {
        let alice = create_root_node(&admin_service, "alice", "alice", true).await;
        let bob = create_node(&admin_service, "bob", "bob", true).await;
        let charlie = create_node(&admin_service, "charlie", "charlie", true).await;

        fund_node(&bitcoind, alice.clone()).await;
        fund_node(&bitcoind, bob.clone()).await;

        open_channel(&bitcoind, alice.clone(), bob.clone(), 1_000_000).await;
        open_channel(&bitcoind, bob.clone(), charlie.clone(), 1_000_000).await;

        // create 50 invoices to pay charlie 10sats
        let invoices = batch_create_invoices(charlie.clone(), 10, 50).await;

        // have alice pay all 50 concurrently by routing through bob
        future::try_join_all(
            invoices
                .into_iter()
                .map(|invoice| pay_invoice(alice.clone(), invoice))
                .map(tokio::spawn),
        )
        .await
        .unwrap();

There's still some work to be done to enable polling / wait_until style code in the tests. Currently it's just waiting some amount of time for funding / channel opens / etc.

I plan on add that functionality to this PR hopefully later today.

johncantrell97 commented 2 years ago

Note: This tests sensei by directly invoking the AdminService and NodeService.

I think we still want e2e tests that can exercise the grpc and http endpoints. devrandom has a python script that uses the grpc api and I'm thinking of writing a quick node script that uses the http api.

I also want to get cypress tests running against the web-admin.

I think once all 4 of these are in place the project will be in a much better place from a testing standpoint going forward.

johncantrell97 commented 2 years ago

Ok this now also includes a bit of a refactor that extracts a "sensei core" lib as described here: #46

It also moves the integration test to the proper place in that library instead of a unit test.