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

Feature/3404 datil dev support #515

Merged
merged 70 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
91278c8
Implement support for running against datil-dev
hwrdtm Jun 20, 2024
7ce9b5e
Hack to make work against datil-dev
hwrdtm Jun 20, 2024
b5df915
feat(tinny): remove `LIT_OFFICIAL_RPC` and add `LIT_RPC` enum to supp…
Ansonhkg Jun 27, 2024
26d181c
chore: fix `testLIT` typo
Ansonhkg Jun 27, 2024
0f4065c
fix: import
Ansonhkg Jun 27, 2024
0f5d175
Merge branch 'dev/test-common-updates' into feature/3404-datil-dev-su…
Ansonhkg Jun 27, 2024
9bf76b5
fix(testing): correct test result reporting in runTestsParallel
Ansonhkg Jun 27, 2024
1d66ed0
feat(test): introduce chunked parallel execution
Ansonhkg Jun 27, 2024
1928396
fix(temp): disabled `switchWallet`
Ansonhkg Jun 27, 2024
fcc0fe2
feat(test): LIT_RPC enum
Ansonhkg Jun 27, 2024
e6139c1
feat: add relayer tests
Ansonhkg Jun 28, 2024
155cacb
feat(tinny): temp disabled wallet switching
Ansonhkg Jun 28, 2024
0fb62e3
feat: add datil relayer support
Ansonhkg Jun 28, 2024
bfe0cac
fix(tinny): Simplify and centralize RPC URL handling
Ansonhkg Jun 28, 2024
83c7382
fix(contracts-sdk): correct rpc for browser
Ansonhkg Jun 28, 2024
3e25698
Update local-tests/README.md
Ansonhkg Jun 28, 2024
462d886
Update local-tests/README.md
Ansonhkg Jun 28, 2024
d7fdea8
Update local-tests/setup/shiva-client.ts
Ansonhkg Jun 28, 2024
efd7404
fix: https://github.com/LIT-Protocol/js-sdk/pull/515/files/83c73821c5…
Ansonhkg Jun 28, 2024
a82fe0b
fix: https://github.com/LIT-Protocol/js-sdk/pull/515/files/83c73821c5…
Ansonhkg Jun 28, 2024
8323088
fix: https://github.com/LIT-Protocol/js-sdk/pull/515/files/83c73821c5…
Ansonhkg Jun 28, 2024
0cdddfd
fix: https://github.com/LIT-Protocol/js-sdk/pull/515/files/83c73821c5…
Ansonhkg Jun 28, 2024
e254cfb
fix: https://github.com/LIT-Protocol/js-sdk/pull/515/files/83c73821c5…
Ansonhkg Jun 28, 2024
9be5559
fix: https://github.com/LIT-Protocol/js-sdk/pull/515/files/83c73821c5…
Ansonhkg Jun 28, 2024
b1db2e9
fix: https://github.com/LIT-Protocol/js-sdk/pull/515/files/83c73821c5…
Ansonhkg Jun 28, 2024
936e3ec
fix: https://github.com/LIT-Protocol/js-sdk/pull/515/files/83c73821c5…
Ansonhkg Jun 28, 2024
4e92c94
fix: https://github.com/LIT-Protocol/js-sdk/pull/515/files/83c73821c5…
Ansonhkg Jun 28, 2024
a96640f
fix: https://github.com/LIT-Protocol/js-sdk/pull/515/files/83c73821c5…
Ansonhkg Jun 28, 2024
985db03
fix: https://github.com/LIT-Protocol/js-sdk/pull/515/files/83c73821c5…
Ansonhkg Jun 28, 2024
a84d509
fix: remove random character in the file
Ansonhkg Jun 28, 2024
8c2ec2d
Merge branch 'feature/3404-datil-dev-support' of https://github.com/L…
Ansonhkg Jun 28, 2024
2697093
Update local-tests/setup/shiva-client.ts
Ansonhkg Jun 28, 2024
2c998f6
Update local-tests/setup/shiva-client.ts
Ansonhkg Jun 28, 2024
220fa4f
fix: https://github.com/LIT-Protocol/js-sdk/pull/515/files#r1659243267
Ansonhkg Jun 28, 2024
d73255f
fix: #r1659249390
Ansonhkg Jun 28, 2024
db52690
fix: #r1659266348
Ansonhkg Jun 28, 2024
3573e0a
Update local-tests/setup/tinny-environment.ts
Ansonhkg Jun 28, 2024
1398224
feat: swap staging url to prod
Ansonhkg Jun 28, 2024
fd3da9e
doc: update version
Ansonhkg Jun 28, 2024
f5fd9da
fix: contiune even if failed to generate internalDev
Ansonhkg Jun 28, 2024
8e48ed9
fix: remove process.exit
Ansonhkg Jun 28, 2024
7fa75b2
refac: Prettier
DashKash54 Jul 1, 2024
4868b11
Published version: 6.1.0@datil-dev
DashKash54 Jul 1, 2024
42a9518
fix(test): LIT-3404 - Allow tinny to be run against Cayenne again
MaximusHaximus Jul 2, 2024
4d98940
fix: LIT-3404 - Normalize `Chronicle` spelling in new changes with ex…
MaximusHaximus Jul 2, 2024
2efb2a2
fix(contracts-sdk): LIT-3404 - Adjust PKP mint methods to set `gasLim…
MaximusHaximus Jul 2, 2024
08e56a2
feat: add custom gas limit
Ansonhkg Jul 2, 2024
bc03da9
Merge branch 'feature/3404-datil-dev-support' into feature/3404-add-m…
Ansonhkg Jul 2, 2024
d8bd3e9
chore: add comment
Ansonhkg Jul 2, 2024
c212647
Merge branch 'feature/3404-add-manual-gas-limit' of https://github.co…
Ansonhkg Jul 2, 2024
7450f8b
fix: gasLimit missing on param
Ansonhkg Jul 2, 2024
a6e145d
fix: param optionality
Ansonhkg Jul 2, 2024
2881f6e
fix: upping default gas limit
Ansonhkg Jul 2, 2024
ddb9982
Merge pull request #519 from LIT-Protocol/feature/3404-add-manual-gas…
Ansonhkg Jul 2, 2024
2b2f120
chore: prettier
Ansonhkg Jul 2, 2024
35add79
Merge branch 'master' of https://github.com/LIT-Protocol/js-sdk into …
Ansonhkg Jul 2, 2024
2a0cdb6
fix: linty lint
Ansonhkg Jul 2, 2024
0f0ce25
feat(wrapped-keys): LIT-3404 - Add support for `datil-dev` to wrapped…
MaximusHaximus Jul 2, 2024
87ce2fd
Merge pull request #520 from LIT-Protocol/feature/3404-datil-dev-supp…
MaximusHaximus Jul 2, 2024
3524f56
feat(lit-core): LIT-3404 - Ensure Datil processes Epoch changes, and …
MaximusHaximus Jul 3, 2024
301b761
fix(wrapped-keys): LIT-3404 - Ensure errors thrown from LIT action ex…
MaximusHaximus Jul 3, 2024
9a4408d
fix(local-tests): LIT-3404 - Fix TS error in testUseValidLitActionCod…
MaximusHaximus Jul 3, 2024
aec70d5
test(wrapped-keys): LIT-3404 - Update wrapped-keys tests for datil co…
MaximusHaximus Jul 3, 2024
34d95b6
test(wrapped-keys): LIT-3404 - Update error string checks on failing …
MaximusHaximus Jul 3, 2024
f88591d
test(wrapped-keys): LIT-3404 - Enable generate key tests
MaximusHaximus Jul 3, 2024
2fbd861
fix(wrapped-keys): LIT-3404 - Enforce salt is always included in `cip…
MaximusHaximus Jul 5, 2024
11051ad
Published version: 6.1.0@wrapped-keys
DashKash54 Jul 6, 2024
221c264
Published version: 6.1.0@datil-dev
DashKash54 Jul 6, 2024
53b0532
refac: Prettier
DashKash54 Jul 6, 2024
51ca628
chore(wrapped-keys): LIT-3404 - Throw error if `generatePrivateKey()`…
MaximusHaximus Jul 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions local-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,21 @@ Below is the API documentation for the `ProcessEnvs` interface, detailing the co

**NOTE: a `.env.sample` is contained in the repository root for the below env tables**

| Variable | Description |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `MAX_ATTEMPTS` | Each test is executed in a loop with a maximum number of attempts specified by `devEnv.processEnvs.MAX_ATTEMPTS`. |
| `NETWORK` | The network to use for testing, which can be one of the following: `LIT_TESTNET.LOCALCHAIN`, `LIT_TESTNET.MANZANO`, or `LIT_TESTNET.CAYENNE`. |
| `DEBUG` | Specifies whether to enable debug mode. |
| `REQUEST_PER_KILOSECOND` | To execute a transaction with Lit, you must reserve capacity on the network using Capacity Credits. These allow a set number of requests over a period (default 2 days). |
| `WAIT_FOR_KEY_INTERVAL` | Wait time in milliseconds if no private keys are available. |
| `TIME_TO_RELEASE_KEY` | Time to wait before releasing the key after requesting it. |
| `RUN_IN_BAND` | Run all tests in a single thread. |
| `RUN_IN_BAND_INTERVAL` | The interval in milliseconds to run the tests in a single thread. |
| `LIT_RPC_URL` | The URL of the Lit RPC server. If running locally on Anvil, it should be 'http://127.0.0.1:8545'. |
| `LIT_OFFICIAL_RPC` | The URL of the official Lit RPC server, usually 'https://chain-rpc.litprotocol.com/http' but can be changed if needed. |
| `USE_SHIVA` | A flag to determine if `Shiva` should be used for the `localchain` network. |
| `PRIVATE_KEYS` | A set of private keys to use which will be used to perform chain operations. |
| Variable | Description |
| ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `MAX_ATTEMPTS` | Each test is executed in a loop with a maximum number of attempts specified by `devEnv.processEnvs.MAX_ATTEMPTS`. |
| `NETWORK` | The network to use for testing, which can be one of the following: `LIT_TESTNET.LOCALCHAIN`, `LIT_TESTNET.MANZANO`, or `LIT_TESTNET.CAYENNE`. |
| `DEBUG` | Specifies whether to enable debug mode. |
| `REQUEST_PER_KILOSECOND` | To execute a transaction with Lit, you must reserve capacity on the network using Capacity Credits. These allow a set number of requests over a period (default 2 days). |
| `WAIT_FOR_KEY_INTERVAL` | Wait time in milliseconds if no private keys are available. |
| `TIME_TO_RELEASE_KEY` | Time to wait before releasing the key after requesting it. |
| `RUN_IN_BAND` | Run all tests in a single thread. |
| `RUN_IN_BAND_INTERVAL` | The interval in milliseconds to run the tests in a single thread. |
| `LIT_RPC_URL` | The URL of the Lit RPC server: <br> - For local Anvil: `http://127.0.0.1:8545` <br> - For Chronical: `https://chain-rpc.litprotocol.com/http` <br> - For Vesuvius: `https://vesuvius-rpc.litprotocol.com` |
| `STOP_TESTNET` | Flag to stop a single running testnet after the test run concludes. |
| `USE_SHIVA` | A flag to determine if `Shiva` should be used for the `localchain` network. |
| `PRIVATE_KEYS` | A set of private keys to use which will be used to perform chain operations. |
| `CHUNK_SIZE` | Determines the number of tests run concurrently during parallel execution |

Below is te API Documentation forthe `ProccessEnvs` interface for the `shiva-client` detailing the configurable enviorment variables and their purposes:

Expand Down
20 changes: 13 additions & 7 deletions local-tests/setup/tinny-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ export enum LIT_TESTNET {
LOCALCHAIN = 'localchain',
MANZANO = 'manzano',
CAYENNE = 'cayenne',
DATIL_DEV = 'datil-dev',
}

export enum LIT_RPC {
LOCAL_ANVIL = 'http://127.0.0.1:8545',
CHRONICAL = 'https://chain-rpc.litprotocol.com/http',
VESUVIUS = 'https://vesuvius-rpc.litprotocol.com',
}

export interface ProcessEnvs {
Expand All @@ -18,6 +25,7 @@ export interface ProcessEnvs {
* - `LIT_TESTNET.LOCALCHAIN`
* - `LIT_TESTNET.MANZANO`
* - `LIT_TESTNET.CAYENNE`
* - `LIT_TESTNET.DATIL_DEV`
*/
NETWORK: LIT_TESTNET;

Expand Down Expand Up @@ -53,14 +61,12 @@ export interface ProcessEnvs {

// =========== In most cases you won't need to change the following values ===========
/**
* The URL of Lit RPC server. If it's running locally on Anvil, it should be 'http://127.0.0.1:8545'
*/
LIT_RPC_URL: string;

/**
* The URL of the official Lit RPC server. Usually 'https://chain-rpc.litprotocol.com/http' but can be changed if needed
* The URL of Lit RPC server.
* - If it's running locally on Anvil, it should be 'http://127.0.0.1:8545'
* - If it's running on Chronical, it should be 'https://chain-rpc.litprotocol.com/http'
* - If it's running on Vesuvius, it should be 'https://vesuvius-rpc.litprotocol.com'
*/
LIT_OFFICIAL_RPC: string;
LIT_RPC_URL: string | null;

/**
* This is usually used when you're running tests locally depending how many nodes you are running.
Expand Down
130 changes: 90 additions & 40 deletions local-tests/setup/tinny-environment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { LIT_TESTNET, ProcessEnvs, TinnyEnvConfig } from './tinny-config';
import {
LIT_RPC,
LIT_TESTNET,
ProcessEnvs,
TinnyEnvConfig,
} from './tinny-config';
import { LitNodeClient } from '@lit-protocol/lit-node-client';
import { LitContracts } from '@lit-protocol/contracts-sdk';
import {
Expand Down Expand Up @@ -29,24 +34,20 @@ export class TinnyEnvironment {
DEBUG: process.env['DEBUG'] === 'true',
REQUEST_PER_KILOSECOND:
parseInt(process.env['REQUEST_PER_KILOSECOND']) || 200,
LIT_RPC_URL: process.env['LIT_RPC_URL'] || 'http://127.0.0.1:8545',
LIT_RPC_URL: process.env['LIT_RPC_URL'],
WAIT_FOR_KEY_INTERVAL:
parseInt(process.env['WAIT_FOR_KEY_INTERVAL']) || 3000,
BOOTSTRAP_URLS: process.env['BOOTSTRAP_URLS']?.split(',') || [
'http://127.0.0.1:7470',
'http://127.0.0.1:7471',
'http://127.0.0.1:7472',
],
LIT_OFFICIAL_RPC:
process.env['LIT_OFFICIAL_RPC'] ||
'https://chain-rpc.litprotocol.com/http',
TIME_TO_RELEASE_KEY: parseInt(process.env['TIME_TO_RELEASE_KEY']) || 10000,
RUN_IN_BAND: process.env['RUN_IN_BAND'] === 'true',
RUN_IN_BAND_INTERVAL: parseInt(process.env['RUN_IN_BAND_INTERVAL']) || 5000,

// Available Accounts
// ==================
// (0) "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" (10000.000000000000000000 ETH)
// (1) "0x70997970C51812dc3A010C7d01b50e0d17dc79C8" (10000.000000000000000000 ETH)
// (2) "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC" (10000.000000000000000000 ETH)
// (3) "0x90F79bf6EB2c4f870365E785982E1f101E93b906" (10000.000000000000000000 ETH)
Expand Down Expand Up @@ -117,10 +118,30 @@ export class TinnyEnvironment {
).fill(false);

// -- setup rpc
if (this.network === LIT_TESTNET.LOCALCHAIN) {
// Map of network names to their corresponding RPC URLs
const RPC_MAP = {
[LIT_TESTNET.LOCALCHAIN]: LIT_RPC.LOCAL_ANVIL,
[LIT_TESTNET.MANZANO]: LIT_RPC.CHRONICAL,
[LIT_TESTNET.DATIL_DEV]: LIT_RPC.VESUVIUS,
};

// -- setup rpc
// Priority:
// 1. Use environment variable if set
// 2. Use RPC_MAP if network is recognized
// 3. Throw error if neither condition is met
if (this.processEnvs.LIT_RPC_URL) {
// If LIT_RPC_URL is set in the environment, use it
this.rpc = this.processEnvs.LIT_RPC_URL;
} else if (this.network in RPC_MAP) {
// If the network is recognized in RPC_MAP, use the corresponding RPC URL
this.rpc = RPC_MAP[this.network];
} else {
this.rpc = this.processEnvs.LIT_OFFICIAL_RPC;
// If neither condition is met, throw an error with available options
const availableNetworks = Object.keys(RPC_MAP).join(', ');
throw new Error(
`No RPC URL found for network "${this.network}". Available networks are: ${availableNetworks}`
);
}

console.log(
Expand Down Expand Up @@ -213,7 +234,7 @@ export class TinnyEnvironment {
this?.testnet?.ContractContext ?? this._contractContext;
this.litNodeClient = new LitNodeClient({
litNetwork: 'custom',
rpcUrl: this.processEnvs.LIT_RPC_URL,
rpcUrl: this.rpc,
debug: this.processEnvs.DEBUG,
checkNodeAttestation: false, // disable node attestation check for local testing
contractContext: networkContext,
Expand Down Expand Up @@ -411,22 +432,34 @@ export class TinnyEnvironment {
this.contractsClient = new LitContracts({
signer: wallet,
debug: this.processEnvs.DEBUG,
rpc: this.processEnvs.LIT_RPC_URL, // anvil rpc
rpc: this.rpc,
customContext: networkContext,
});
});F
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

? F 🤣

Suggested change
});F
});

// TODO: This wallet should be cached somehwere and reused to create delegation signatures.
// There is a correlation between the number of Capacity Credit NFTs in a wallet and the speed at which nodes can verify a given rate limit authorization. Creating a single wallet to hold all Capacity Credit NFTs improves network performance during tests.
const capacityCreditWallet =
ethers.Wallet.createRandom().connect(provider);

const transferTx = await wallet.sendTransaction({
to: capacityCreditWallet.address,
value: ethers.utils.parseEther('0.001'),
});
await transferTx.wait();
async function _switchWallet() {
// TODO: This wallet should be cached somehwere and reused to create delegation signatures.
// There is a correlation between the number of Capacity Credit NFTs in a wallet and the speed at which nodes can verify a given rate limit authorization. Creating a single wallet to hold all Capacity Credit NFTs improves network performance during tests.
const capacityCreditWallet =
ethers.Wallet.createRandom().connect(provider);

// get wallet balance
const balance = await wallet.getBalance();
console.log('this.rpc:', this.rpc);
console.log('this.wallet.address', wallet.address);
console.log('Balance:', balance.toString());

const transferTx = await wallet.sendTransaction({
to: capacityCreditWallet.address,
value: ethers.utils.parseEther('0.001'),
});
await transferTx.wait();
}

// await _switchWallet();

this.contractsClient = new LitContracts({
signer: capacityCreditWallet,
// signer: capacityCreditWallet, // disabled switch wallet for now
signer: wallet,
debug: this.processEnvs.DEBUG,
network: this.network,
});
Expand All @@ -439,23 +472,40 @@ export class TinnyEnvironment {
* Mint a Capacity Credits NFT and get a capacity delegation authSig with it
* ====================================
*/
console.log(
'[𐬺🧪 Tinny Environment𐬺] Mint a Capacity Credits NFT and get a capacity delegation authSig with it'
);
const capacityTokenId = (
await this.contractsClient.mintCapacityCreditsNFT({
requestsPerKilosecond: this.processEnvs.REQUEST_PER_KILOSECOND,
daysUntilUTCMidnightExpiration: 2,
})
).capacityTokenIdStr;

this.superCapacityDelegationAuthSig = (
await this.litNodeClient.createCapacityDelegationAuthSig({
dAppOwnerWallet: wallet,
capacityTokenId: capacityTokenId,
// Sets a maximum limit of 200 times that the delegation can be used and prevents usage beyond it
uses: '200',
})
).capacityDelegationAuthSig;

// Disabled for now
async function _mintSuperCapacityDelegationAuthSig() {
console.log(
'[𐬺🧪 Tinny Environment𐬺] Mint a Capacity Credits NFT and get a capacity delegation authSig with it'
);
try {
const capacityTokenId = (
await this.contractsClient.mintCapacityCreditsNFT({
requestsPerKilosecond: this.processEnvs.REQUEST_PER_KILOSECOND,
daysUntilUTCMidnightExpiration: 2,
})
).capacityTokenIdStr;

this.superCapacityDelegationAuthSig = (
await this.litNodeClient.createCapacityDelegationAuthSig({
dAppOwnerWallet: wallet,
capacityTokenId: capacityTokenId,
// Sets a maximum limit of 200 times that the delegation can be used and prevents usage beyond it
uses: '200',
})
).capacityDelegationAuthSig;
} catch (e: any) {
if (
e.message.includes(`Can't allocate capacity beyond the global max`)
) {
console.log('❗️Skipping capacity delegation auth sig setup.', e);
} else {
console.log(
'❗️Error while setting up capacity delegation auth sig',
e
);
}
}
}
};
}
Loading
Loading