-
Notifications
You must be signed in to change notification settings - Fork 757
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1067 from starknet-io/next-version
Next version
- Loading branch information
Showing
73 changed files
with
1,364 additions
and
2,090 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
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
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 |
---|---|---|
@@ -1,2 +1,10 @@ | ||
/* Default test config based on run `starknet-devnet --seed 0` */ | ||
export const GS_DEFAULT_TEST_PROVIDER_URL = 'http://127.0.0.1:5050/'; | ||
|
||
export const LOCAL_DEVNET_NOT_RUNNING_MESSAGE = ` | ||
Local devnet is not running. In order to properly run it you need to do the following: \n | ||
- Go to the: https://hub.docker.com/r/shardlabs/starknet-devnet-rs/tags | ||
- Find the latest tag and copy the "docker pull" command | ||
- Run Docker on your machine | ||
- Run the command: "docker pull shardlabs/starknet-devnet-rs:latest" | ||
`; |
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,64 @@ | ||
/* eslint-disable no-console */ | ||
import { GS_DEFAULT_TEST_PROVIDER_URL } from '../constants'; | ||
|
||
class AccountResolver { | ||
get providedUrl() { | ||
return process.env.TEST_RPC_URL; | ||
} | ||
|
||
get hasAllAccountEnvs() { | ||
return process.env.TEST_ACCOUNT_ADDRESS && process.env.TEST_ACCOUNT_PRIVATE_KEY; | ||
} | ||
|
||
get hasPartialAccountEnvs() { | ||
return process.env.TEST_ACCOUNT_ADDRESS || process.env.TEST_ACCOUNT_PRIVATE_KEY; | ||
} | ||
|
||
private async fetchAccount(url: string) { | ||
const response = await fetch(`${url}predeployed_accounts`); | ||
const [account] = await response.json(); | ||
const { address, private_key, initial_balance } = account; | ||
process.env.TEST_ACCOUNT_ADDRESS = address; | ||
process.env.TEST_ACCOUNT_PRIVATE_KEY = private_key; | ||
process.env.INITIAL_BALANCE = initial_balance; | ||
} | ||
|
||
private async isAccountSet(isDevnet: boolean): Promise<boolean> { | ||
if (this.hasAllAccountEnvs) { | ||
return true; | ||
} | ||
if (this.hasPartialAccountEnvs) { | ||
throw new Error( | ||
'If you are providing one of you need to provide both: TEST_ACCOUNT_ADDRESS & TEST_ACCOUNT_PRIVATE_KEY' | ||
); | ||
} | ||
if (isDevnet) { | ||
// get account from devnet | ||
try { | ||
await this.fetchAccount(GS_DEFAULT_TEST_PROVIDER_URL); | ||
return true; | ||
} catch (error) { | ||
console.error('Fetching account from devnet failed'); | ||
} | ||
} else if (this.providedUrl) { | ||
// try to get it from remote devnet | ||
try { | ||
await this.fetchAccount(this.providedUrl); | ||
return true; | ||
} catch (error) { | ||
console.error(`Fetching account from provided url ${this.providedUrl} failed`); | ||
} | ||
} | ||
|
||
throw new Error( | ||
'Setting Account using all known strategies failed, provide basic test parameters' | ||
); | ||
} | ||
|
||
async execute(isDevnet: boolean): Promise<void> { | ||
const isAccountSet = await this.isAccountSet(isDevnet); | ||
if (isAccountSet) console.log('Detected Account'); | ||
} | ||
} | ||
|
||
export default new AccountResolver(); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.