testing.rst 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. Solang Test Suite
  2. =================
  3. Solang has a few test suites. These are all run on each pull request via
  4. `github actions <https://github.com/hyperledger-solang/solang/actions>`_.
  5. Solidity parser and semantics tests
  6. -----------------------------------
  7. In the `tests <https://github.com/hyperledger-solang/solang/tree/main/tests>`_ directory, there are
  8. a lot of tests which call `fn parse_and_resolve()`. This function parses Solidity, and returns
  9. the *namespace*: all the resolved contracts, types, functions, etc (as much as could be resolved),
  10. and all the compiler diagnostics, i.e. compiler warnings and errors. These tests check that
  11. the compiler parser and semantic analysis work correctly.
  12. Note that Solidity can import other solidity files using the ``import`` statement. There are further
  13. tests which create a file cache with filenames and their contents, to ensure that imports
  14. work as expected.
  15. Codegen tests
  16. -------------
  17. The stage after semantic analysis is codegen. Codegen generates an IR which is a CFG, so it is
  18. simply called CFG. The codegen tests ensure that the CFG matches what should be created. These
  19. tests are inspired by LLVM lit tests. The tests can found in
  20. `codegen_testcases <https://github.com/hyperledger-solang/solang/tree/main/tests/codegen_testcases>`_.
  21. These tests do the following:
  22. - Look for a comment ``// RUN:`` and then run the compiler with the given arguments and the filename itself
  23. - After that the output is compared against special comments:
  24. - ``// CHECK:`` means that following output must be present
  25. - ``// BEGIN-CHECK:`` means check for the following output but scan the output from the beginning
  26. - ``// FAIL:`` will check that the command will fail (non-zero exit code) with the following output
  27. Mock contract virtual machine
  28. -----------------------------
  29. For Polkadot and Solana there is a mock virtual machine. System and runtime call
  30. implementations should semantically represent the real on-chain virtual machine as exact as
  31. possible. Aspects that don't matter in the context of unit testing (e.g. gas-metering) may be
  32. ignored in the mock virtual machine. For Polkadot, this uses the
  33. `wasmi crate <https://crates.io/crates/wasmi>`_ and for Solana it
  34. uses the `Solana RBPF crate <https://crates.io/crates/solana_rbpf>`_.
  35. These tests consist of calling a function call `fn build_solidity()` which compiles the given
  36. solidity source code and then returns a `VM`. This `VM` can be used to deploy one
  37. of the contract, and test various functions like contract storage, accessing builtins such as
  38. block height, or creating/calling other contracts. Since the functionality is mocked, the test
  39. can do targeted introspection to see if the correct function was called, or walk the heap
  40. of the contract working memory to ensure there are no corruptions.
  41. Deploy contract on dev chain
  42. ----------------------------
  43. There are some tests in `integration <https://github.com/hyperledger-solang/solang/tree/main/integration/>`_
  44. which are written in node. These tests start an actual real chain via containers,
  45. and then deploying some tests contracts to them and interacting with them.