How to use onlySupported method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

index.ts

Source:index.ts Github

copy

Full Screen

1import { chains as chainParams } from './chains'2import { hardforks as hardforkChanges } from './hardforks'3import { Chain } from './types'4interface hardforkOptions {5 /** optional, only allow supported HFs (default: false) */6 onlySupported?: boolean7 /** optional, only active HFs (default: false) */8 onlyActive?: boolean9}10/**11 * Common class to access chain and hardfork parameters12 */13export default class Common {14 private _hardfork: string | null15 private _supportedHardforks: Array<string>16 private _chainParams: Chain17 /**18 * Creates a Common object for a custom chain, based on a standard one. It uses all the [[Chain]]19 * params from [[baseChain]] except the ones overridden in [[customChainParams]].20 *21 * @param baseChain The name (`mainnet`) or id (`1`) of a standard chain used to base the custom22 * chain params on.23 * @param customChainParams The custom parameters of the chain.24 * @param hardfork String identifier ('byzantium') for hardfork (optional)25 * @param supportedHardforks Limit parameter returns to the given hardforks (optional)26 */27 static forCustomChain(28 baseChain: string | number,29 customChainParams: Partial<Chain>,30 hardfork?: string | null,31 supportedHardforks?: Array<string>,32 ): Common {33 const standardChainParams = Common._getChainParams(baseChain)34 return new Common(35 {36 ...standardChainParams,37 ...customChainParams,38 },39 hardfork,40 supportedHardforks,41 )42 }43 private static _getChainParams(chain: string | number): Chain {44 if (typeof chain === 'number') {45 if (chainParams['names'][chain]) {46 return chainParams[chainParams['names'][chain]]47 }48 throw new Error(`Chain with ID ${chain} not supported`)49 }50 if (chainParams[chain]) {51 return chainParams[chain]52 }53 throw new Error(`Chain with name ${chain} not supported`)54 }55 /**56 * @constructor57 * @param chain String ('mainnet') or Number (1) chain58 * @param hardfork String identifier ('byzantium') for hardfork (optional)59 * @param supportedHardforks Limit parameter returns to the given hardforks (optional)60 */61 constructor(62 chain: string | number | object,63 hardfork?: string | null,64 supportedHardforks?: Array<string>,65 ) {66 this._chainParams = this.setChain(chain)67 this._hardfork = null68 this._supportedHardforks = supportedHardforks === undefined ? [] : supportedHardforks69 if (hardfork) {70 this.setHardfork(hardfork)71 }72 }73 /**74 * Sets the chain75 * @param chain String ('mainnet') or Number (1) chain76 * representation. Or, a Dictionary of chain parameters for a private network.77 * @returns The dictionary with parameters set as chain78 */79 setChain(chain: string | number | object): any {80 if (typeof chain === 'number' || typeof chain === 'string') {81 this._chainParams = Common._getChainParams(chain)82 } else if (typeof chain === 'object') {83 const required = ['networkId', 'genesis', 'hardforks', 'bootstrapNodes']84 for (const param of required) {85 if ((<any>chain)[param] === undefined) {86 throw new Error(`Missing required chain parameter: ${param}`)87 }88 }89 this._chainParams = chain as Chain90 } else {91 throw new Error('Wrong input format')92 }93 return this._chainParams94 }95 /**96 * Sets the hardfork to get params for97 * @param hardfork String identifier ('byzantium')98 */99 setHardfork(hardfork: string | null): void {100 if (!this._isSupportedHardfork(hardfork)) {101 throw new Error(`Hardfork ${hardfork} not set as supported in supportedHardforks`)102 }103 let changed = false104 for (const hfChanges of hardforkChanges) {105 if (hfChanges[0] === hardfork) {106 this._hardfork = hardfork107 changed = true108 }109 }110 if (!changed) {111 throw new Error(`Hardfork with name ${hardfork} not supported`)112 }113 }114 /**115 * Internal helper function to choose between hardfork set and hardfork provided as param116 * @param hardfork Hardfork given to function as a parameter117 * @returns Hardfork chosen to be used118 */119 _chooseHardfork(hardfork?: string | null, onlySupported?: boolean): string {120 onlySupported = onlySupported === undefined ? true : onlySupported121 if (!hardfork) {122 if (!this._hardfork) {123 throw new Error('Method called with neither a hardfork set nor provided by param')124 } else {125 hardfork = this._hardfork126 }127 } else if (onlySupported && !this._isSupportedHardfork(hardfork)) {128 throw new Error(`Hardfork ${hardfork} not set as supported in supportedHardforks`)129 }130 return hardfork131 }132 /**133 * Internal helper function, returns the params for the given hardfork for the chain set134 * @param hardfork Hardfork name135 * @returns Dictionary with hardfork params136 */137 _getHardfork(hardfork: string): any {138 const hfs = this.hardforks()139 for (const hf of hfs) {140 if (hf['name'] === hardfork) return hf141 }142 throw new Error(`Hardfork ${hardfork} not defined for chain ${this.chainName()}`)143 }144 /**145 * Internal helper function to check if a hardfork is set to be supported by the library146 * @param hardfork Hardfork name147 * @returns True if hardfork is supported148 */149 _isSupportedHardfork(hardfork: string | null): boolean {150 if (this._supportedHardforks.length > 0) {151 for (const supportedHf of this._supportedHardforks) {152 if (hardfork === supportedHf) return true153 }154 } else {155 return true156 }157 return false158 }159 /**160 * Returns the parameter corresponding to a hardfork161 * @param topic Parameter topic ('gasConfig', 'gasPrices', 'vm', 'pow', 'casper', 'sharding')162 * @param name Parameter name (e.g. 'minGasLimit' for 'gasConfig' topic)163 * @param hardfork Hardfork name, optional if hardfork set164 */165 param(topic: string, name: string, hardfork?: string): any {166 hardfork = this._chooseHardfork(hardfork)167 let value168 for (const hfChanges of hardforkChanges) {169 if (!hfChanges[1][topic]) {170 throw new Error(`Topic ${topic} not defined`)171 }172 if (hfChanges[1][topic][name] !== undefined) {173 value = hfChanges[1][topic][name].v174 }175 if (hfChanges[0] === hardfork) break176 }177 if (value === undefined) {178 throw new Error(`${topic} value for ${name} not found`)179 }180 return value181 }182 /**183 * Returns a parameter for the hardfork active on block number184 * @param topic Parameter topic185 * @param name Parameter name186 * @param blockNumber Block number187 */188 paramByBlock(topic: string, name: string, blockNumber: number): any {189 const activeHfs = this.activeHardforks(blockNumber)190 const hardfork = activeHfs[activeHfs.length - 1]['name']191 return this.param(topic, name, hardfork)192 }193 /**194 * Checks if set or provided hardfork is active on block number195 * @param hardfork Hardfork name or null (for HF set)196 * @param blockNumber197 * @param opts Hardfork options (onlyActive unused)198 * @returns True if HF is active on block number199 */200 hardforkIsActiveOnBlock(201 hardfork: string | null,202 blockNumber: number,203 opts?: hardforkOptions,204 ): boolean {205 opts = opts !== undefined ? opts : {}206 const onlySupported = opts.onlySupported === undefined ? false : opts.onlySupported207 hardfork = this._chooseHardfork(hardfork, onlySupported)208 const hfBlock = this.hardforkBlock(hardfork)209 if (hfBlock !== null && blockNumber >= hfBlock) return true210 return false211 }212 /**213 * Alias to hardforkIsActiveOnBlock when hardfork is set214 * @param blockNumber215 * @param opts Hardfork options (onlyActive unused)216 * @returns True if HF is active on block number217 */218 activeOnBlock(blockNumber: number, opts?: hardforkOptions): boolean {219 return this.hardforkIsActiveOnBlock(null, blockNumber, opts)220 }221 /**222 * Sequence based check if given or set HF1 is greater than or equal HF2223 * @param hardfork1 Hardfork name or null (if set)224 * @param hardfork2 Hardfork name225 * @param opts Hardfork options226 * @returns True if HF1 gte HF2227 */228 hardforkGteHardfork(229 hardfork1: string | null,230 hardfork2: string,231 opts?: hardforkOptions,232 ): boolean {233 opts = opts !== undefined ? opts : {}234 const onlyActive = opts.onlyActive === undefined ? false : opts.onlyActive235 hardfork1 = this._chooseHardfork(hardfork1, opts.onlySupported)236 let hardforks237 if (onlyActive) {238 hardforks = this.activeHardforks(null, opts)239 } else {240 hardforks = this.hardforks()241 }242 let posHf1 = -1,243 posHf2 = -1244 let index = 0245 for (const hf of hardforks) {246 if (hf['name'] === hardfork1) posHf1 = index247 if (hf['name'] === hardfork2) posHf2 = index248 index += 1249 }250 return posHf1 >= posHf2251 }252 /**253 * Alias to hardforkGteHardfork when hardfork is set254 * @param hardfork Hardfork name255 * @param opts Hardfork options256 * @returns True if hardfork set is greater than hardfork provided257 */258 gteHardfork(hardfork: string, opts?: hardforkOptions): boolean {259 return this.hardforkGteHardfork(null, hardfork, opts)260 }261 /**262 * Checks if given or set hardfork is active on the chain263 * @param hardfork Hardfork name, optional if HF set264 * @param opts Hardfork options (onlyActive unused)265 * @returns True if hardfork is active on the chain266 */267 hardforkIsActiveOnChain(hardfork?: string | null, opts?: hardforkOptions): boolean {268 opts = opts !== undefined ? opts : {}269 const onlySupported = opts.onlySupported === undefined ? false : opts.onlySupported270 hardfork = this._chooseHardfork(hardfork, onlySupported)271 for (const hf of this.hardforks()) {272 if (hf['name'] === hardfork && hf['block'] !== null) return true273 }274 return false275 }276 /**277 * Returns the active hardfork switches for the current chain278 * @param blockNumber up to block if provided, otherwise for the whole chain279 * @param opts Hardfork options (onlyActive unused)280 * @return Array with hardfork arrays281 */282 activeHardforks(blockNumber?: number | null, opts?: hardforkOptions): Array<any> {283 opts = opts !== undefined ? opts : {}284 const activeHardforks = []285 const hfs = this.hardforks()286 for (const hf of hfs) {287 if (hf['block'] === null) continue288 if (blockNumber !== undefined && blockNumber !== null && blockNumber < hf['block']) break289 if (opts.onlySupported && !this._isSupportedHardfork(hf['name'])) continue290 activeHardforks.push(hf)291 }292 return activeHardforks293 }294 /**295 * Returns the latest active hardfork name for chain or block or throws if unavailable296 * @param blockNumber up to block if provided, otherwise for the whole chain297 * @param opts Hardfork options (onlyActive unused)298 * @return Hardfork name299 */300 activeHardfork(blockNumber?: number | null, opts?: hardforkOptions): string {301 opts = opts !== undefined ? opts : {}302 const activeHardforks = this.activeHardforks(blockNumber, opts)303 if (activeHardforks.length > 0) {304 return activeHardforks[activeHardforks.length - 1]['name']305 } else {306 throw new Error(`No (supported) active hardfork found`)307 }308 }309 /**310 * Returns the hardfork change block for hardfork provided or set311 * @param hardfork Hardfork name, optional if HF set312 * @returns Block number313 */314 hardforkBlock(hardfork?: string): number {315 hardfork = this._chooseHardfork(hardfork, false)316 return this._getHardfork(hardfork)['block']317 }318 /**319 * True if block number provided is the hardfork (given or set) change block of the current chain320 * @param blockNumber Number of the block to check321 * @param hardfork Hardfork name, optional if HF set322 * @returns True if blockNumber is HF block323 */324 isHardforkBlock(blockNumber: number, hardfork?: string): boolean {325 hardfork = this._chooseHardfork(hardfork, false)326 if (this.hardforkBlock(hardfork) === blockNumber) {327 return true328 } else {329 return false330 }331 }332 /**333 * Provide the consensus type for the hardfork set or provided as param334 * @param hardfork Hardfork name, optional if hardfork set335 * @returns Consensus type (e.g. 'pow', 'poa')336 */337 consensus(hardfork?: string): string {338 hardfork = this._chooseHardfork(hardfork)339 return this._getHardfork(hardfork)['consensus']340 }341 /**342 * Provide the finality type for the hardfork set or provided as param343 * @param {String} hardfork Hardfork name, optional if hardfork set344 * @returns {String} Finality type (e.g. 'pos', null of no finality)345 */346 finality(hardfork?: string): string {347 hardfork = this._chooseHardfork(hardfork)348 return this._getHardfork(hardfork)['finality']349 }350 /**351 * Returns the Genesis parameters of current chain352 * @returns Genesis dictionary353 */354 genesis(): any {355 return (<any>this._chainParams)['genesis']356 }357 /**358 * Returns the hardforks for current chain359 * @returns {Array} Array with arrays of hardforks360 */361 hardforks(): any {362 return (<any>this._chainParams)['hardforks']363 }364 /**365 * Returns bootstrap nodes for the current chain366 * @returns {Dictionary} Dict with bootstrap nodes367 */368 bootstrapNodes(): any {369 return (<any>this._chainParams)['bootstrapNodes']370 }371 /**372 * Returns the hardfork set373 * @returns Hardfork name374 */375 hardfork(): string | null {376 return this._hardfork377 }378 /**379 * Returns the Id of current chain380 * @returns chain Id381 */382 chainId(): number {383 return <number>(<any>this._chainParams)['chainId']384 }385 /**386 * Returns the name of current chain387 * @returns chain name (lower case)388 */389 chainName(): string {390 return chainParams['names'][this.chainId()] || (<any>this._chainParams)['name']391 }392 /**393 * Returns the Id of current network394 * @returns network Id395 */396 networkId(): number {397 return (<any>this._chainParams)['networkId']398 }...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1const chainParams = require('./chains')2const hardforkChanges = require('./hardforks')3/**4 * Common class to access chain and hardfork parameters5 */6class SECCommon {7 /**8 * @constructor9 * @param {String|Number} chain String ('mainnet') or Number (1) chain representation10 * @param {String} hardfork String identifier ('byzantium') for hardfork (optional)11 * @param {Array} supportedHardforks Limit parameter returns to the given hardforks (optional)12 */13 constructor (chain, hardfork, supportedHardforks) {14 this.setChain(chain)15 this._hardfork = null16 this._supportedHardforks = supportedHardforks === undefined ? [] : supportedHardforks17 if (hardfork) {18 this.setHardfork(hardfork)19 }20 }21 /**22 * Sets the chain23 * @param {String|Number} chain String ('mainnet') or Number (1) chain representation24 */25 setChain (chain) {26 if (typeof (chain) === 'number') {27 if (chainParams['names'][chain]) {28 this._chainParams = chainParams[chainParams['names'][chain]]29 } else {30 throw new Error(`Chain with ID ${chain} not supported`)31 }32 } else if (typeof (chain) === 'string') {33 if (chainParams[chain]) {34 this._chainParams = chainParams[chain]35 } else {36 throw new Error(`Chain with name ${chain} not supported`)37 }38 } else {39 throw new Error('Wrong input format')40 }41 }42 /**43 * Sets the hardfork to get params for44 * @param {String} hardfork String identifier ('byzantium')45 */46 setHardfork (hardfork) {47 if (!this._isSupportedHardfork(hardfork)) {48 throw new Error(`Hardfork ${hardfork} not set as supported in supportedHardforks`)49 }50 let changed = false51 for (let hfChanges of hardforkChanges) {52 if (hfChanges[0] === hardfork) {53 this._hardfork = hardfork54 changed = true55 }56 }57 if (!changed) {58 throw new Error(`Hardfork with name ${hardfork} not supported`)59 }60 }61 /**62 * Internal helper function to choose between hardfork set and hardfork provided as param63 * @param {String} hardfork Hardfork given to function as a parameter64 * @returns {String} Hardfork chosen to be used65 */66 _chooseHardfork (hardfork, onlySupported) {67 onlySupported = onlySupported === undefined ? true : onlySupported68 if (!hardfork) {69 if (!this._hardfork) {70 throw new Error('Method called with neither a hardfork set nor provided by param')71 } else {72 hardfork = this._hardfork73 }74 } else if (!this._isSupportedHardfork(hardfork)) {75 throw new Error(`Hardfork ${hardfork} not set as supported in supportedHardforks`)76 }77 return hardfork78 }79 /**80 * Internal helper function, returns the params for the given hardfork for the chain set81 * @param {String} hardfork Hardfork name82 * @returns {Dictionary}83 */84 _getHardfork (hardfork) {85 let hfs = this.hardforks()86 for (let hf of hfs) {87 if (hf['name'] === hardfork) return hf88 }89 throw new Error(`Hardfork ${hardfork} not defined for chain ${this.chainName()}`)90 }91 /**92 * Internal helper function to check if a hardfork is set to be supported by the library93 * @param {String} hardfork Hardfork name94 * @returns {Boolean} True if hardfork is supported95 */96 _isSupportedHardfork (hardfork) {97 if (this._supportedHardforks.length > 0) {98 for (let supportedHf of this._supportedHardforks) {99 if (hardfork === supportedHf) return true100 }101 } else {102 return true103 }104 return false105 }106 /**107 * Returns the parameter corresponding to a hardfork108 * @param {String} topic Parameter topic ('gasConfig', 'gasPrices', 'vm', 'pow', 'casper', 'sharding')109 * @param {String} name Parameter name (e.g. 'minGasLimit' for 'gasConfig' topic)110 * @param {String} hardfork Hardfork name, optional if hardfork set111 */112 param (topic, name, hardfork) {113 hardfork = this._chooseHardfork(hardfork)114 let value115 for (let hfChanges of hardforkChanges) {116 if (!hfChanges[1][topic]) {117 throw new Error(`Topic ${topic} not defined`)118 }119 if (hfChanges[1][topic][name] !== undefined) {120 value = hfChanges[1][topic][name].v121 }122 if (hfChanges[0] === hardfork) break123 }124 if (value === undefined) {125 throw new Error(`${topic} value for ${name} not found`)126 }127 return value128 }129 /**130 * Returns a parameter for the hardfork active on block number131 * @param {String} topic Parameter topic132 * @param {String} name Parameter name133 * @param {Number} blockNumber Block number134 */135 paramByBlock (topic, name, blockNumber) {136 let activeHfs = this.activeHardforks(blockNumber)137 let hardfork = activeHfs[activeHfs.length - 1]['name']138 return this.param(topic, name, hardfork)139 }140 /**141 * Checks if set or provided hardfork is active on block number142 * @param {String} hardfork Hardfork name or null (for HF set)143 * @param {Number} blockNumber144 * @param {Array} opts145 * @param {Array.Boolean} opts.onlySupported optional, only allow supported HFs (default: false)146 * @returns {Boolean}147 */148 hardforkIsActiveOnBlock (hardfork, blockNumber, opts) {149 opts = opts !== undefined ? opts : []150 let onlySupported = opts.onlySupported === undefined ? false : opts.onlySupported151 hardfork = this._chooseHardfork(hardfork, onlySupported)152 let hfBlock = this.hardforkBlock(hardfork)153 if (hfBlock !== null && blockNumber >= hfBlock) return true154 return false155 }156 /**157 * Alias to hardforkIsActiveOnBlock when hardfork is set158 * @param {Number} blockNumber159 * @param {Array} opts160 * @param {Array.Boolean} opts.onlySupported optional, only allow supported HFs (default: false)161 * @returns {Boolean}162 */163 activeOnBlock (blockNumber, opts) {164 return this.hardforkIsActiveOnBlock(null, blockNumber, opts)165 }166 /**167 * Sequence based check if given or set HF1 is greater than or equal HF2168 * @param {String} hardfork1 Hardfork name or null (if set)169 * @param {String} hardfork2 Hardfork name170 * @param {Array} opts171 * @param {Array.Boolean} opts.onlyActive optional, only active HFs (default: false)172 * @param {Array.Boolean} opts.onlySupported optional, only allow supported HFs (default: false)173 * @returns {Boolean}174 */175 hardforkGteHardfork (hardfork1, hardfork2, opts) {176 opts = opts !== undefined ? opts : []177 let onlyActive = opts.onlyActive === undefined ? false : opts.onlyActive178 hardfork1 = this._chooseHardfork(hardfork1, opts.onlySupported)179 let hardforks180 if (onlyActive) {181 hardforks = this.activeHardforks(null, opts)182 } else {183 hardforks = this.hardforks()184 }185 let posHf1, posHf2186 let index = 0187 for (let hf of hardforks) {188 if (hf['name'] === hardfork1) posHf1 = index189 if (hf['name'] === hardfork2) posHf2 = index190 index += 1191 }192 return posHf1 >= posHf2193 }194 /**195 * Alias to hardforkGteHardfork when hardfork is set196 * @param {String} hardfork Hardfork name197 * @param {Array} opts198 * @param {Array.Boolean} opts.onlyActive optional, only active HFs (default: false)199 * @param {Array.Boolean} opts.onlySupported optional, only allow supported HFs (default: false)200 * @returns {Boolean}201 */202 gteHardfork (hardfork, opts) {203 return this.hardforkGteHardfork(null, hardfork, opts)204 }205 /**206 * Checks if given or set hardfork is active on the chain207 * @param {String} hardfork Hardfork name, optional if HF set208 * @param {Array} opts209 * @param {Array.Boolean} opts.onlySupported optional, only allow supported HFs (default: false)210 * @returns {Boolean}211 */212 hardforkIsActiveOnChain (hardfork, opts) {213 opts = opts !== undefined ? opts : []214 let onlySupported = opts.onlySupported === undefined ? false : opts.onlySupported215 hardfork = this._chooseHardfork(hardfork, onlySupported)216 for (let hf of this.hardforks()) {217 if (hf['name'] === hardfork && hf['block'] !== null) return true218 }219 return false220 }221 /**222 * Returns the active hardfork switches for the current chain223 * @param {Number} blockNumber up to block if provided, otherwise for the whole chain224 * @param {Array} opts225 * @param {Array.Boolean} opts.onlySupported optional, limit results to supported HFs (default: false)226 * @return {Array} Array with hardfork arrays227 */228 activeHardforks (blockNumber, opts) {229 opts = opts !== undefined ? opts : []230 let activeHardforks = []231 let hfs = this.hardforks()232 for (let hf of hfs) {233 if (hf['block'] === null) continue234 if ((blockNumber !== undefined && blockNumber !== null) && blockNumber < hf['block']) break235 if (opts.onlySupported && !this._isSupportedHardfork(hf['name'])) continue236 activeHardforks.push(hf)237 }238 return activeHardforks239 }240 /**241 * Returns the latest active hardfork name for chain or block or throws if unavailable242 * @param {Number} blockNumber up to block if provided, otherwise for the whole chain243 * @param {Array} opts244 * @param {Array.Boolean} opts.onlySupported optional, limit results to supported HFs (default: false)245 * @return {String} Hardfork name246 */247 activeHardfork (blockNumber, opts) {248 let activeHardforks = this.activeHardforks(blockNumber, opts)249 if (activeHardforks.length > 0) {250 return activeHardforks[activeHardforks.length - 1]['name']251 } else {252 throw new Error(`No (supported) active hardfork found`)253 }254 }255 /**256 * Returns the hardfork change block for hardfork provided or set257 * @param {String} hardfork Hardfork name, optional if HF set258 * @returns {Number} Block number259 */260 hardforkBlock (hardfork) {261 hardfork = this._chooseHardfork(hardfork, false)262 return this._getHardfork(hardfork)['block']263 }264 /**265 * True if block number provided is the hardfork (given or set) change block of the current chain266 * @param {Number} blockNumber Number of the block to check267 * @param {String} hardfork Hardfork name, optional if HF set268 * @returns {Boolean}269 */270 isHardforkBlock (blockNumber, hardfork) {271 hardfork = this._chooseHardfork(hardfork, false)272 if (this.hardforkBlock(hardfork) === blockNumber) {273 return true274 } else {275 return false276 }277 }278 /**279 * Provide the consensus type for the hardfork set or provided as param280 * @param {String} hardfork Hardfork name, optional if hardfork set281 * @returns {String} Consensus type (e.g. 'pow', 'poa')282 */283 consensus (hardfork) {284 hardfork = this._chooseHardfork(hardfork)285 return this._getHardfork(hardfork)['consensus']286 }287 /**288 * Provide the finality type for the hardfork set or provided as param289 * @param {String} hardfork Hardfork name, optional if hardfork set290 * @returns {String} Finality type (e.g. 'pos', null of no finality)291 */292 finality (hardfork) {293 hardfork = this._chooseHardfork(hardfork)294 return this._getHardfork(hardfork)['finality']295 }296 /**297 * Returns the Genesis parameters of current chain298 * @returns {Dictionary} Genesis dict299 */300 genesis () {301 return this._chainParams['genesis']302 }303 /**304 * Returns the hardforks for current chain305 * @returns {Array} Array with arrays of hardforks306 */307 hardforks () {308 return this._chainParams['hardforks']309 }310 /**311 * Returns bootstrap nodes for the current chain312 * @returns {Dictionary} Dict with bootstrap nodes313 */314 bootstrapNodes () {315 return this._chainParams['bootstrapNodes']316 }317 /**318 * Returns the hardfork set319 * @returns {String} Hardfork name320 */321 hardfork () {322 return this._hardfork323 }324 /**325 * Returns the Id of current chain326 * @returns {Number} chain Id327 */328 chainId () {329 return this._chainParams['chainId']330 }331 /**332 * Returns the name of current chain333 * @returns {String} chain name (lower case)334 */335 chainName () {336 return chainParams['names'][this.chainId()]337 }338 /**339 * Returns the Id of current network340 * @returns {Number} network Id341 */342 networkId () {343 return this._chainParams['networkId']344 }345}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2var device = new stf.Device(stfClient, 'device serial');3device.onlySupported().then(function(device){4 console.log(device);5}).catch(function(err){6 console.log(err);7});8var stf = require('devicefarmer-stf-client');9var device = new stf.Device(stfClient, 'device serial');10device.onlySupported().then(function(device){11 console.log(device);12}).catch(function(err){13 console.log(err);14});15var stf = require('devicefarmer-stf-client');16var device = new stf.Device(stfClient, 'device serial');17device.onlySupported().then(function(device){18 console.log(device);19}).catch(function(err){20 console.log(err);21});22var stf = require('devicefarmer-stf-client');23var device = new stf.Device(stfClient, 'device serial');24device.onlySupported().then(function(device){25 console.log(device);26}).catch(function(err){27 console.log(err);28});29var stf = require('devicefarmer-stf-client');30var device = new stf.Device(stfClient, 'device serial');31device.onlySupported().then(function(device){32 console.log(device);33}).catch(function(err){34 console.log(err);35});36var stf = require('devicefarmer-stf-client');

Full Screen

Using AI Code Generation

copy

Full Screen

1var devicefarmer = require('devicefarmer-stf-client');2var client = devicefarmer.createClient({3});4var device = devicefarmer.createDevice({5});6client.onlySupported(device, function (err, res) {7 if (err) {8 console.log(err);9 } else {10 console.log(res);11 }12});13{ serial: 'emulator-5554',14 provider: { channel: 'local' },15 network: { connected: true, roaming: false },16 battery: { present: true, level: 100, scale: 100, status: 2 },17 phone: { network: 'UNKNOWN', operator: null, sim: 'UNKNOWN', subscriber: null },18 display: { id: 0, width: 1080, height: 1920, xdpi: 420.469, ydpi: 420.469, fps: 60, density: 3, rotation: 0, secure: true },19 screenSize: { width: 1080, height: 1920 },20 features: { android.hardware.touchscreen: true, android.hardware.faketouch: true, android.hardware.screen.portrait: true, android.hardware.screen.landscape: true, android.hardware.camera: true, android.hardware.camera.autofocus: true, android.hardware.camera.flash: true, android.hardware.camera.front: true, android.hardware

Full Screen

Using AI Code Generation

copy

Full Screen

1var devicefarmer = require('devicefarmer-stf');2stf.onlySupported({api:19, abi:"armeabi-v7a", manufacturer:"samsung", model:"SM-G900F", resolution:"1920x1080", network:"lte", operator:"vodafone", country:"de"}, function(err, devices) {3 console.log(devices);4});5var devicefarmer = require('devicefarmer-stf');6stf.onlySupported({api:19, abi:"armeabi-v7a", manufacturer:"samsung", model:"SM-G900F", resolution:"1920x1080", network:"lte", operator:"vodafone", country:"de"}, function(err, devices) {7 console.log(devices);8});9var devicefarmer = require('devicefarmer-stf');10stf.onlySupported({api:19, abi:"armeabi-v7a", manufacturer:"samsung", model:"SM-G900F", resolution:"1920x1080", network:"lte", operator:"vodafone", country:"de"}, function(err, devices) {11 console.log(devices);12});13var devicefarmer = require('devicefarmer-stf');14stf.onlySupported({api:19, abi:"armeabi-v7a", manufacturer:"samsung", model:"SM-G900F", resolution:"1920x1080", network:"lte", operator:"vodafone", country:"de"}, function(err, devices) {15 console.log(devices);16});17var devicefarmer = require('devicefarmer-stf');18stf.onlySupported({api:19, abi:"armeabi-v7a", manufacturer:"samsung

Full Screen

Using AI Code Generation

copy

Full Screen

1var util = require('util');2var DeviceFarmerClient = require('devicefarmer-stf-client');3var device = client.getDevice('HTC One_M8');4device.supported().then(function(supported) {5 console.log(util.inspect(supported, {depth: null, colors: true}));6});7{ 'android.supported': true,8 'shell': 'sh' }9DeviceFarmerClient.prototype.supported = function() {10 var self = this;11 return self.getDeviceProperties().then(function(properties) {12 var supported = true;13 Object.keys(properties).forEach(function(key) {14 if (key.indexOf('android.supported') === 0) {15 supported = supported && properties[key];16 }17 });18 return supported;19 });20};21DeviceFarmerClient.prototype.getDeviceProperties = function() {22 var self = this;23 return self._request({24 }).then(function(response) {25 return response.body;26 });27};28var util = require('util');29var DeviceFarmerClient = require('devicefarmer-stf-client');30var device = client.getDevice('HTC One_M8');31device.supported().then(function(supported) {32 console.log(util.inspect(supported, {depth: null, colors: true}));33});

Full Screen

Using AI Code Generation

copy

Full Screen

1var sf = require('devicefarmer-stf');2var device = new sf.Device();3device.onlySupported('test.js',function(err,devices){4 if(err){5 console.log(err);6 }7 else{8 console.log(devices);9 }10});11[ { serial: '0123456789ABCDEF',12 cpu: 'ARMv7 Processor rev 3 (v7l)',

Full Screen

Using AI Code Generation

copy

Full Screen

1var utils = require('devicefarmer-stf-utils');2var device = utils.getDevice();3var supported = device.onlySupported(['Nexus 5', 'Nexus 6']);4console.log(supported);5var utils = require('devicefarmer-stf-utils');6var device = utils.getDevice();7var supported = device.onlySupported(['Nexus 5', 'Nexus 6'], 'Nexus 4');8console.log(supported);9var utils = require('devicefarmer-stf-utils');10var device = utils.getDevice();11device.onlySupported(['Nexus 5', 'Nexus 6']);12console.log('Device is supported');13var utils = require('devicefarmer-stf-utils');14var device = utils.getDevice();15device.onlySupported(['Nexus 5', 'Nexus 6'], 'Nexus 4');16console.log('Device is supported');17var utils = require('devicefarmer-stf-utils');18var device = utils.getDevice();19device.onlySupported(['Nexus 5', 'Nexus 6']);20console.log('Device is supported');21var utils = require('devicefarmer-stf-utils');22var device = utils.getDevice();23device.onlySupported(['Nexus 5', 'Nexus 6'], 'Nexus 4');24console.log('Device is supported');

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf');2var test = function() {3 var deviceList = device.getDevices();4 deviceList.then(function(result) {5 console.log(result);6 });7}8test();9var stf = require('devicefarmer-stf');10var test = function() {11 var deviceList = device.getDevices();12 deviceList.then(function(result) {13 console.log(result);14 });15}16test();17var stf = require('devicefarmer-stf');18var test = function() {19 var deviceList = device.getDevices();20 deviceList.then(function(result) {21 console.log(result);22 });23}24test();25var stf = require('devicefarmer-stf');26var test = function() {27 var deviceList = device.getDevices();28 deviceList.then(function(result) {29 console.log(result);30 });31}32test();

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf');2device.onlySupported(function (err, devices) {3 if (err) {4 console.log(err);5 } else {6 console.log(devices);7 if (devices.length > 0) {8 device.use(devices[0].serial, function (err, serial) {9 if (err) {10 console.log(err);11 } else {12 console.log(serial);13 }14 });15 }16 }17});18var stf = require('devicefarmer-stf');19device.onlySupported(function (err, devices) {20 if (err) {21 console.log(err);22 } else {23 console.log(devices);24 if (devices.length > 0) {25 device.use(devices[0].serial, function (err, serial) {26 if (err) {27 console.log(err);28 } else {29 console.log(serial);30 }31 });32 }33 }34});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run devicefarmer-stf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful