-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,801 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,5 @@ yarn-error.log | |
!.yarn/plugins | ||
!.yarn/sdks | ||
!.yarn/versions | ||
|
||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { expect } from 'chai' | ||
import { Centrifuge } from '../Centrifuge.js' | ||
import { TenderlyFork } from './tenderly.js' | ||
import { sepolia } from 'viem/chains' | ||
import { parseEther } from 'viem' | ||
|
||
describe('Centrifuge', () => { | ||
let centrifuge: Centrifuge | ||
let tenderlyFork: TenderlyFork | ||
|
||
before(async () => { | ||
tenderlyFork = await TenderlyFork.create(sepolia) | ||
centrifuge = new Centrifuge({ | ||
environment: 'demo', | ||
rpcUrls: { | ||
11155111: tenderlyFork.rpcUrl, | ||
}, | ||
}) | ||
centrifuge.setSigner(tenderlyFork.signer) | ||
}) | ||
// TODO: don't remove if any test fails | ||
// after(async () => { | ||
// return await tenderlyFork.deleteTenderlyRpcEndpoint() | ||
// }) | ||
it('should be connected to sepolia', async () => { | ||
const client = centrifuge.getClient() | ||
expect(client?.chain.id).to.equal(11155111) | ||
const chains = centrifuge.chains | ||
expect(chains).to.include(11155111) | ||
}) | ||
it('should fetch account and balances', async () => { | ||
const account = await centrifuge.account('0x423420Ae467df6e90291fd0252c0A8a637C1e03f') | ||
const balances = await account.balances() | ||
expect(balances).to.exist | ||
}) | ||
|
||
it('should make a transfer', async () => { | ||
await Promise.all([ | ||
tenderlyFork.fundAccountEth(tenderlyFork.account.address, parseEther('100')), | ||
tenderlyFork.fundAccountERC20(tenderlyFork.account.address, parseEther('100')), | ||
]) | ||
const account = await centrifuge.account(tenderlyFork.account.address) | ||
const balances = await account.balances() | ||
expect(Number(balances)).to.be.greaterThan(0) | ||
// doesn't work: ERC20/insufficient-balance, the tenderly signer does not match the sender of the transfer | ||
// const transfer = await account.transfer('0x423420Ae467df6e90291fd0252c0A8a637C1e03f', parseEther('10')) | ||
// if ('receipt' in transfer) { | ||
// expect(transfer.receipt.status).to.equal('success') | ||
// } else { | ||
// throw new Error('Transfer failed') | ||
// } | ||
}) | ||
|
||
it('should fetch a pool by id', async () => { | ||
const pool = await centrifuge.pool('4139607887') | ||
expect(pool).to.exist | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
## Testing with Mocha and Tenderly | ||
|
||
Tenderly allows us to create a local Ethereum network that is compatible with Ethereum Mainnet that we can use to run our tests against. A new fork will be created for each test suite. | ||
|
||
### Local setup | ||
|
||
1. Visit [Tenderly](https://dashboard.tenderly.co/) and create an account if you don't have one. | ||
|
||
2. Create a new project. | ||
|
||
3. Settings is where you will find the values for the environment variables `TENDERLY_ACCESS_KEY` and `TENDERLY_ACCOUNT_SLUG` and `TENDERLY_PROJECT_SLUG` | ||
|
||
4. Copy `env.example` file to `.env` and add the values you found in the previous step. | ||
|
||
Install dependencies: | ||
|
||
```bash | ||
yarn | ||
``` | ||
|
||
Run the tests: | ||
|
||
```bash | ||
yarn test | ||
``` | ||
|
||
### Usage | ||
|
||
```ts | ||
// create a new fork | ||
const tenderlyFork = await TenderlyFork.create(sepolia) | ||
|
||
// or use an existing fork | ||
const tenderlyFork = new TenderlyFork(sepolia, '<vnet-id>') | ||
|
||
// connect to centrifuge | ||
const centrifuge = new Centrifuge({ | ||
environment: 'demo', | ||
rpcUrls: { | ||
11155111: tenderlyFork.rpcUrl, | ||
}, | ||
}) | ||
|
||
// set the tenderly signer as the signer for centrifuge | ||
centrifuge.setSigner(tenderlyFork.signer) | ||
|
||
// fund the signer's account on the fork | ||
await tenderlyFork.fundAccountEth(tenderlyFork.account.address, parseEther('100')) | ||
|
||
// fund the signer's account with USDt ERC20 tokens | ||
await tenderlyFork.fundAccountERC20(tenderlyFork.account.address, parseEther('100')) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
TENDERLY_ACCESS_KEY= | ||
PROJECT_SLUG= | ||
ACCOUNT_SLUG= |
Oops, something went wrong.