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

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

TorstenStueber
Copy link
Member

@TorstenStueber TorstenStueber commented Feb 19, 2024

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:

@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
Member 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
Member 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
Member 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
Member 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
Member 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
Member Author

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

TorstenStueber and others added 2 commits April 19, 2024 14:27
This is in order to use the deployed npm version with types available
ts-node was not running due to module vs commonjs issues
because it's deprecated and the pull command throws an error

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
Member 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
Member 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
Member 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
Member Author

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

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