Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

39 implement tests for nabla indexer #40

Merged
merged 3 commits into from
Oct 9, 2024

Conversation

TorstenStueber
Copy link
Contributor

@TorstenStueber TorstenStueber commented Feb 19, 2024

This now ballooned into one big PR that contains many different changes implemented over months.

Updated deployment instructions

We deployed a number of various Nabla instances in the past: different instances on Pendulum (used for Vortex and public deployments) and instances on Foucoco (used for the testnet campaign and for different validations and testing scenarios).

There was only one definition of the deployment scripts and when changing to a new deployment I had to adapt all files locally. This had a couple of issues:

  • no record of historic deployment definitions
  • editing the files was error prone as names had to be changed consistently across multiple files
  • I had a lot of inconsistent local changes to this repository that never ended up as a proper PR – this is one of the reasons why this now such a big PR

Instead, I now changed the deployment scripts to use declarative deployments (see the folder nabla/deployments). That way editing is less error prone and we can easily keep a history of deployments.

For that reason there is no need for separate nabla and nabla-pendulum projects anymore. There is now just a pendulum project.

Updated Tests

Closes #39
Closes #44
Closes #43 (fixed by this)

This PR adds a new test suite to test the Nabla indexer (called nabla-indexer).

These tests are implemented for this indexer PR: pendulum-chain/pendulum-squids#52.

The main file is nabla-indexer/test/indexer_tests.ts.

Additionally this ticket also updates the version of the Nabla contracts that had some minor changes in the mean time and some new tests have been implemented.

This is temporary work. The intention is to move these tests to our subsquid indexer repository and to move the Nabla tests to the Nabla contracts repository. However, this requires that wasm-deploy becomes a standalone tool that can be used in other npm projects (see #10).

Additionally, this PR adds some small new features to wasm-deploy that were necessary to implement this test suite:

Other Changes

  • update all dependencies, particularly api-solang
  • make tsx a dev dependency instead of a normal dependency
  • add lint:ts script

@TorstenStueber TorstenStueber linked an issue Feb 19, 2024 that may be closed by this pull request
@TorstenStueber TorstenStueber marked this pull request as draft February 19, 2024 13:06
@TorstenStueber TorstenStueber marked this pull request as ready for review February 19, 2024 13:06
@@ -63,6 +63,44 @@ export default async function (environment: TestSuiteEnvironment) {
await genericTestOnlyOwnerCanSetPoolCap(pool, environment);
},

async test_maxCoverageRatioForSwapIn_CheckDefaultValue() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@gianfra-t gianfra-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good 👍! I only have minor questions, not on the logic of the test itself. That so far seems sound.
I still haven't run the code locally.

nabla-indexer/test/indexer_tests.ts Show resolved Hide resolved
(routers) =>
routers
.find((router) => router.id === address(instance.router))
?.swapPools.find((swapPool) => swapPool.id === address(replacementPool)) !== undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also check that the replaced swapPool does not exist anymore (not registered with the router)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think this is happening here already the verifyIndexer that comes up next checks whether there are only two swap pools. Since the first swap pool's reserve changed from 11000000000000 to 20000000000000 and there are only two pools, then this would mean that the indexer does not report the replaced swap pool anymore.


verifyIndexer(indexerRouters, instance, [
{
reserve: "12997193504712",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an "easy" way to calculate these values without having to use the full equation of the curve? (or at least an approximation to do a sanity check)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, among others, the root of a quadratic equation. That's why this number looks so random. I think that does not count as "easy" anymore.

},
]);
},

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check to see if the balances were modified to reflect the swap? Or is it too much coupling on the same test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What balances do you refer to? The pool token balance(s) and/or the LP token balance(s)? As these are not reported by the indexer and, e.g., the Nabla UI reads them directly from the smart contract, I don't actually consider this a necessity of this test suite. Is that what you are referring to?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I was referring to the tester balance before and after the swap. What I don't remember is why I thought this could be needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it fine if we leave that out?

@TorstenStueber TorstenStueber force-pushed the 39-implement-tests-for-nabla-indexer branch from cbf80ac to 7e2d214 Compare April 16, 2024 07:01
@TorstenStueber
Copy link
Contributor Author

I added and adapted the tests in order to incorporate the new changes on this branch: https://github.com/0xamberhq/contracts/pull/111


Clone the solang repository and build it:

```shell

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the path to the solang binary used here should be absolute.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if we make it absolute then every developer definitely needs to touch that path. If we keep it relative we just have to make sure that the directory is put into the conventional place.

@TorstenStueber
Copy link
Contributor Author

TorstenStueber commented May 23, 2024

I had to add some changes to make the indexer tests run again: this requires an older version of our wrapper contracts because foucoco-standalone is currently incompatible with the latest main branch of the wrapper contracts (they now assume that there are multiple chain extensions in place – as is the case for our our normal runtimes).

I changed the dependency on the wrapper contracts to refer to an older commit.

Furthermore, the tests require a version of foucoco-standalone that includes PR pendulum-chain/foucoco-standalone#10.

@ebma
Copy link
Member

ebma commented Jun 13, 2024

@TorstenStueber I wanted to test this again, this time using our custom Foucoco version that we added to the pendulum repo. That runtime uses the latest chain extensions and thus has to be called with the chain extension ID + function ID as is done by the latest Pendulum solidity wrapper contracts. So I run the Foucoco testchain with

cargo run -p pendulum-node -- --chain foucoco-standalone --instant-seal

Then I spin up the indexer with

sqd process:local
sqd serve

but when I do npm run test:nabla:local I get the following error:


> [email protected] test:nabla:local
> tsx src/index.ts test nabla --network local

Load project in folder "nabla"
Connecting to chain ws://127.0.0.1:9944
Connected to chain Foucoco-Standalone
Process test suite TestableERC20Tests.ts
Deploying new contract TestableERC20Wrapper
Successfully deployed contract TestableERC20Wrapper to 6h14TV9JVsMwgsgZdLpuEtTYb3kASZDWiwqXJ1Jw9zQq3A9m
Deploying new contract TestableERC20Wrapper
Successfully deployed contract TestableERC20Wrapper to 6mvu7FA1d8bpibtsDxD9junBx2gyEhZfWHzSDfL7QusRjD17


Run test testMintsNative
Deploying new contract TestableERC20Wrapper
Successfully deployed contract TestableERC20Wrapper to 6jCRE1pB1waV1Wdut4F9awnRDSWw5WuZUnUGa1JreYsuk6jK
Deploying new contract TestableERC20Wrapper
Successfully deployed contract TestableERC20Wrapper to 6kN3djWWpyjjcz5gM24KCQfcexRuHKPgxBkis24QKF9s44vn
Run setup code testMintsNative
Run test function testMintsNative
Call contract TestableERC20Wrapper at address 6jCRE1pB1waV1Wdut4F9awnRDSWw5WuZUnUGa1JreYsuk6jK totalSupply []
Done TestableERC20Wrapper totalSupply 199,999,239,999,750,253,600
Call contract TestableERC20Wrapper at address 6jCRE1pB1waV1Wdut4F9awnRDSWw5WuZUnUGa1JreYsuk6jK mint [
  '6k6gXPB9idebCxqSJuqpjPaqfYLQbdLHhvsANH8Dg8GQN3tT',
  10000000000000000n
]

An error occurred
Other
CallError: Other
    at Object.deployedContract.<computed> (/Users/marcel/Documents/wasm-deploy/src/commands/test.ts:253:21)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Object.testMintsNative (/Users/marcel/Documents/wasm-deploy/nabla/test/TestableERC20Tests.ts:25:7)
    at processTestScripts (/Users/marcel/Documents/wasm-deploy/src/commands/test.ts:417:11)
    at <anonymous> (/Users/marcel/Documents/wasm-deploy/src/commands/test.ts:35:5)
    at createAnimatedTextContext (/Users/marcel/Documents/wasm-deploy/src/utils/terminal.ts:155:5)
    at runTestSuits (/Users/marcel/Documents/wasm-deploy/src/commands/test.ts:34:22)
    at Command.<anonymous> (/Users/marcel/Documents/wasm-deploy/src/commandLine.ts:37:7)

and when I do `` I get

[...long list of logs of deployed contracts with events...]
Contract event 6jXDP7ZnQXfkgf8634fx5zUFpgJJrqdVD3rRDtWLRK1Czu1U 008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a481b791897e40faa497cc132bcd10160bc2f5e03a5a85b2323573df8799efc066f00a0724e18090000000000000000000000000000000000000000000000000000
Decoded event Transfer [
  {
    name: 'from',
    value: '6k6gXPB9idebCxqSJuqpjPaqfYLQbdLHhvsANH8Dg8GQN3tT'
  },
  {
    name: 'to',
    value: '6hVczyTideD7rqQWdzgfMLUxJTrzoqRNEz9ZipWzAjxkw1MW'
  },
  { name: 'value', value: '10,000,000,000,000' }
]
Contract event 6hVczyTideD7rqQWdzgfMLUxJTrzoqRNEz9ZipWzAjxkw1MW 078eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a4800a0724e1809000000000000000000000000000000000000000000000000000000a0724e18090000000000000000000000000000000000000000000000000000
Decoded event Mint [
  {
    name: 'sender',
    value: '6k6gXPB9idebCxqSJuqpjPaqfYLQbdLHhvsANH8Dg8GQN3tT'
  },
  { name: 'poolSharesMinted', value: '10,000,000,000,000' },
  { name: 'amountPrincipleDeposited', value: '10,000,000,000,000' }
]
Done BackstopPool deposit [ '10,000,000,000,000', '0' ]
stopPrank

An error occurred
(expected true, got false)
AssertionError [AssertError]: (expected true, got false)
    at assertTrue (/Users/marcel/Documents/wasm-deploy/src/testing/stdLib.ts:24:11)
    at Object.testStandard (/Users/marcel/Documents/wasm-deploy/nabla-indexer/test/indexer_tests.ts:273:7)
    at processTestScripts (/Users/marcel/Documents/wasm-deploy/src/commands/test.ts:417:11)
    at <anonymous> (/Users/marcel/Documents/wasm-deploy/src/commands/test.ts:35:5)
    at createAnimatedTextContext (/Users/marcel/Documents/wasm-deploy/src/utils/terminal.ts:155:5)
    at runTestSuits (/Users/marcel/Documents/wasm-deploy/src/commands/test.ts:34:22)
    at Command.<anonymous> (/Users/marcel/Documents/wasm-deploy/src/commandLine.ts:37:7)

Do we need to touch the tests again or am I doing something wrong?

@TorstenStueber
Copy link
Contributor Author

@ebma Yes, Foucoco Standalone is not working anymore with the master branch of the wrapper contracts. I will change the code so that it will use an older commit of the wrapper contracts where the change to multiple chain extensions did not happen.

This is meant to be temporary. Either we change foucoco-standalone to also use multiple chain extensions or we wait for everything in this comment being completed. I prefer the latter.

@TorstenStueber
Copy link
Contributor Author

I read your comment more thoroughly now. Your comment was about the test run of the nabla project as well as about the nabla-indexer project, correct?

For the nabla-indexer the problem seems to be that events are not correctly decoded anymore. The auto generated decodeEvent function is returning events (correctly decoded) but all of them lack the __kind field (e.g. here) that we need to use to distinguish events. For that reason none of the code for event processing is executed anymore.

@ebma
Copy link
Member

ebma commented Aug 9, 2024

@TorstenStueber but you investigated this problem already and identified that this is due to some breaking changes in one of the dependencies, right? How should we proceed with this PR?

@TorstenStueber
Copy link
Contributor Author

@ebma I waited for #50 to be resolved next will check how to get this PR here back on track.

@TorstenStueber TorstenStueber force-pushed the 39-implement-tests-for-nabla-indexer branch from 4a236aa to 48bf572 Compare October 8, 2024 06:56
Create nabla-indexer project

Remove unnecessary contracts

Allow to override metadata message names

Allow to override argument names of messages in metadata

Include new tests from Nabla main repo

Update README

Use different token decimals for Nabla testnet deployment

Update names in deployment script

Add deployment for five swap pools

Adapt tests for new changes

Implement test from Alpha Testnet

Add tests for swap pool quote functions

Implement tests to change treasury

Add missing calls to Nabla deployment

Remove `api-solang` from workspaces
This is in order to use the deployed npm version with types available

Replace ts-node with tsx
ts-node was not running due to module vs commonjs issues

Remove `--ignore-engines`
because it's deprecated and the pull command throws an error

Change `init` for 'nablaCurve' repo to "npm"

Set polkadot dependencies to fixed version
There was a breaking change in a minor version bump so we set these to specific versions
see polkadot-js/api@ca48023#diff-6c3c68a16db206b507cabe5612726492ebaf4c9f3d4717e10d2a75b3d6dcd4f1R172

Rename commands in package.json

Add info to README.md

Add fixes to make nabla indexer tests successful again

Change token names and symbols in testnet deployment

Create debug snapshot

Simplify Nabla project
@TorstenStueber TorstenStueber force-pushed the 39-implement-tests-for-nabla-indexer branch from 48bf572 to 18133a2 Compare October 8, 2024 08:02
@TorstenStueber
Copy link
Contributor Author

@pendulum-chain/devs I added a lot of updates to this PR and updated the description of this PR. Additionally I rebased it so that it is not in conflict with master anymore.

Since this PR has been open and had many changes over many months, I recommend the following course of actions:

@gianfra-t
Copy link
Contributor

I approved so we can continue with that plan. I believe we also ice boxed the standalone issue right?

@TorstenStueber
Copy link
Contributor Author

I would need to check in the next weeks what the latest version in our discussion about the standalone issue was and whether there is any chance to continue. I don't consider this high priority right now as long as we don't change the Nabla code.

@TorstenStueber TorstenStueber merged commit 4adc32a into main Oct 9, 2024
@TorstenStueber TorstenStueber deleted the 39-implement-tests-for-nabla-indexer branch October 9, 2024 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants