-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: eth_getTransactionCount can return 0x0 const if configured (#1389)
* feat: add configuration on hardhat provider * feat: add configuration on hardhat plugin with tests
- Loading branch information
1 parent
f4ec03e
commit 07f8f63
Showing
10 changed files
with
484 additions
and
7 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
64 changes: 64 additions & 0 deletions
64
packages/hardhat-plugin/tests/eth_getTransactionCount-default-value-project.unit.test.ts
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 @@ | ||
import { afterEach, beforeEach, describe, expect, test } from '@jest/globals'; | ||
|
||
import { resetHardhatContext } from 'hardhat/plugins-testing'; | ||
import { | ||
type HardhatRuntimeEnvironment, | ||
type HttpNetworkConfig | ||
} from 'hardhat/types'; | ||
import { setHardhatContext } from './test-utils'; | ||
|
||
/** | ||
* Simple hardhat project eth_getTransactionCount-default-value-project network configuration defined | ||
* | ||
* @group unit/eth_getTransactionCount-default-value-project | ||
*/ | ||
describe('Using eth_getTransactionCount with default value as 0x0', () => { | ||
/** | ||
* Init hardhat runtime environment | ||
*/ | ||
let hre: HardhatRuntimeEnvironment; | ||
|
||
beforeEach(async function () { | ||
// Set hardhat context | ||
setHardhatContext('eth_getTransactionCount-default-value-project'); | ||
|
||
// Load hardhat environment | ||
hre = await import('hardhat'); | ||
}); | ||
|
||
afterEach(function () { | ||
resetHardhatContext(); | ||
}); | ||
|
||
/** | ||
* Test suite for eth_getTransactionCount with default 0x0 value | ||
*/ | ||
describe('Custom network configuration hardhat', () => { | ||
/** | ||
* Positive test cases for createWalletFromHardhatNetworkConfig function | ||
*/ | ||
test('Should be able to get a default value of 0x0 from a project', async () => { | ||
// Network configuration should be defined | ||
expect(hre.config.networks.vechain_testnet).toBeDefined(); | ||
|
||
// Initialize network configuration AND check ethGetTransactionCountDefaultValue parameter | ||
const networkConfig = hre.config.networks | ||
.vechain_testnet as HttpNetworkConfig; | ||
expect( | ||
networkConfig.rpcConfiguration | ||
?.ethGetTransactionCountMustReturn0 | ||
).toBe(true); | ||
|
||
// Get the provider | ||
expect(hre.VeChainProvider).toBeDefined(); | ||
const provider = hre.VeChainProvider; | ||
|
||
// Expect 0 as the default value | ||
const request = await provider?.request({ | ||
method: 'eth_getTransactionCount', | ||
params: ['0x0b41c56e19c5151122568873a039fEa090937Fe2', 'latest'] | ||
}); | ||
expect(request).toBe('0x0'); | ||
}); | ||
}); | ||
}); |
64 changes: 64 additions & 0 deletions
64
packages/hardhat-plugin/tests/eth_getTransactionCount-no-value-project.unit.test.ts
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 @@ | ||
import { afterEach, beforeEach, describe, expect, test } from '@jest/globals'; | ||
|
||
import { resetHardhatContext } from 'hardhat/plugins-testing'; | ||
import { | ||
type HardhatRuntimeEnvironment, | ||
type HttpNetworkConfig | ||
} from 'hardhat/types'; | ||
import { setHardhatContext } from './test-utils'; | ||
|
||
/** | ||
* Simple hardhat project eth_getTransactionCount-no-value-project network configuration defined | ||
* | ||
* @group unit/eth_getTransactionCount-no-value-project | ||
*/ | ||
describe('Using eth_getTransactionCount with no options specified. So it will return a random number', () => { | ||
/** | ||
* Init hardhat runtime environment | ||
*/ | ||
let hre: HardhatRuntimeEnvironment; | ||
|
||
beforeEach(async function () { | ||
// Set hardhat context | ||
setHardhatContext('eth_getTransactionCount-no-value-project'); | ||
|
||
// Load hardhat environment | ||
hre = await import('hardhat'); | ||
}); | ||
|
||
afterEach(function () { | ||
resetHardhatContext(); | ||
}); | ||
|
||
/** | ||
* Test suite for eth_getTransactionCount with random value when no options are specified | ||
*/ | ||
describe('Custom network configuration hardhat', () => { | ||
/** | ||
* Should be able to get a random value from a project when no options are specified | ||
*/ | ||
test('Should be able to get a random value from a project when no options are specified', async () => { | ||
// Network configuration should be defined | ||
expect(hre.config.networks.vechain_testnet).toBeDefined(); | ||
|
||
// Initialize network configuration AND check ethGetTransactionCountDefaultValue parameter | ||
const networkConfig = hre.config.networks | ||
.vechain_testnet as HttpNetworkConfig; | ||
expect( | ||
networkConfig.rpcConfiguration | ||
?.ethGetTransactionCountMustReturn0 | ||
).toBe(undefined); | ||
|
||
// Get the provider | ||
expect(hre.VeChainProvider).toBeDefined(); | ||
const provider = hre.VeChainProvider; | ||
|
||
// Expect 0 as the default value | ||
const request = await provider?.request({ | ||
method: 'eth_getTransactionCount', | ||
params: ['0x0b41c56e19c5151122568873a039fEa090937Fe2', 'latest'] | ||
}); | ||
expect(request).not.toBe('0x0'); | ||
}); | ||
}); | ||
}); |
64 changes: 64 additions & 0 deletions
64
packages/hardhat-plugin/tests/eth_getTransactionCount-random-value-project.unit.test.ts
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 @@ | ||
import { afterEach, beforeEach, describe, expect, test } from '@jest/globals'; | ||
|
||
import { resetHardhatContext } from 'hardhat/plugins-testing'; | ||
import { | ||
type HardhatRuntimeEnvironment, | ||
type HttpNetworkConfig | ||
} from 'hardhat/types'; | ||
import { setHardhatContext } from './test-utils'; | ||
|
||
/** | ||
* Simple hardhat project eth_getTransactionCount-random-value-project network configuration defined | ||
* | ||
* @group unit/eth_getTransactionCount-random-value-project | ||
*/ | ||
describe('Using eth_getTransactionCount with random value (not the default 0x0 value)', () => { | ||
/** | ||
* Init hardhat runtime environment | ||
*/ | ||
let hre: HardhatRuntimeEnvironment; | ||
|
||
beforeEach(async function () { | ||
// Set hardhat context | ||
setHardhatContext('eth_getTransactionCount-random-value-project'); | ||
|
||
// Load hardhat environment | ||
hre = await import('hardhat'); | ||
}); | ||
|
||
afterEach(function () { | ||
resetHardhatContext(); | ||
}); | ||
|
||
/** | ||
* Test suite for eth_getTransactionCount with random value | ||
*/ | ||
describe('Custom network configuration hardhat', () => { | ||
/** | ||
* Should be able to get random value from eth_getTransactionCount | ||
*/ | ||
test('Should be able to get random value from eth_getTransactionCount', async () => { | ||
// Network configuration should be defined | ||
expect(hre.config.networks.vechain_testnet).toBeDefined(); | ||
|
||
// Initialize network configuration AND check ethGetTransactionCountDefaultValue parameter | ||
const networkConfig = hre.config.networks | ||
.vechain_testnet as HttpNetworkConfig; | ||
expect( | ||
networkConfig.rpcConfiguration | ||
?.ethGetTransactionCountMustReturn0 | ||
).toBe(false); | ||
|
||
// Get the provider | ||
expect(hre.VeChainProvider).toBeDefined(); | ||
const provider = hre.VeChainProvider; | ||
|
||
// Expect 0 as the default value | ||
const request = await provider?.request({ | ||
method: 'eth_getTransactionCount', | ||
params: ['0x0b41c56e19c5151122568873a039fEa090937Fe2', 'latest'] | ||
}); | ||
expect(request).not.toBe('0x0'); | ||
}); | ||
}); | ||
}); |
64 changes: 64 additions & 0 deletions
64
...sts/hardhat-mock-projects/eth_getTransactionCount-default-value-project/hardhat.config.ts
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 @@ | ||
/** | ||
* Simple hardhat configuration for testing with a VeChain network defined | ||
*/ | ||
|
||
// We load the plugin here. | ||
import { type HardhatUserConfig, type HttpNetworkConfig } from 'hardhat/types'; | ||
|
||
import '../../../src/index'; | ||
import { HDKey } from '@vechain/sdk-core'; | ||
|
||
/** | ||
* Simple configuration for testing | ||
*/ | ||
const vechainTestNetwork: HttpNetworkConfig = { | ||
// Default network parameters | ||
url: 'https://testnet.vechain.org', | ||
timeout: 20000, | ||
httpHeaders: {}, | ||
gas: 'auto', | ||
gasPrice: 'auto', | ||
gasMultiplier: 1, | ||
accounts: { | ||
mnemonic: | ||
'vivid any call mammal mosquito budget midnight expose spirit approve reject system', | ||
path: HDKey.VET_DERIVATION_PATH, | ||
count: 3, | ||
initialIndex: 0, | ||
passphrase: 'VeChainThor' | ||
}, | ||
|
||
// Custom parameters | ||
delegator: { | ||
delegatorPrivateKey: | ||
'ea5383ac1f9e625220039a4afac6a7f868bf1ad4f48ce3a1dd78bd214ee4ace5' | ||
}, | ||
debug: true, | ||
enableDelegation: true, | ||
|
||
// Custom RPC | ||
rpcConfiguration: { | ||
ethGetTransactionCountMustReturn0: true | ||
} | ||
}; | ||
|
||
/** | ||
* Hardhat configuration | ||
*/ | ||
const config: HardhatUserConfig = { | ||
solidity: '0.8.17', | ||
networks: { | ||
vechain_testnet: vechainTestNetwork | ||
}, | ||
|
||
/** | ||
* @note: here we set vechain_testnet as the default network to simulate a command like this: | ||
* | ||
* ```sh | ||
* npx hardhat --network vechain_testnet <command> | ||
* ``` | ||
*/ | ||
defaultNetwork: 'vechain_testnet' | ||
}; | ||
|
||
export default config; |
62 changes: 62 additions & 0 deletions
62
...in/tests/hardhat-mock-projects/eth_getTransactionCount-no-value-project/hardhat.config.ts
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,62 @@ | ||
/** | ||
* Simple hardhat configuration for testing with a VeChain network defined | ||
*/ | ||
|
||
// We load the plugin here. | ||
import { type HardhatUserConfig, type HttpNetworkConfig } from 'hardhat/types'; | ||
|
||
import '../../../src/index'; | ||
import { HDKey } from '@vechain/sdk-core'; | ||
|
||
/** | ||
* Simple configuration for testing | ||
*/ | ||
const vechainTestNetwork: HttpNetworkConfig = { | ||
// Default network parameters | ||
url: 'https://testnet.vechain.org', | ||
timeout: 20000, | ||
httpHeaders: {}, | ||
gas: 'auto', | ||
gasPrice: 'auto', | ||
gasMultiplier: 1, | ||
accounts: { | ||
mnemonic: | ||
'vivid any call mammal mosquito budget midnight expose spirit approve reject system', | ||
path: HDKey.VET_DERIVATION_PATH, | ||
count: 3, | ||
initialIndex: 0, | ||
passphrase: 'VeChainThor' | ||
}, | ||
|
||
// Custom parameters | ||
delegator: { | ||
delegatorPrivateKey: | ||
'ea5383ac1f9e625220039a4afac6a7f868bf1ad4f48ce3a1dd78bd214ee4ace5' | ||
}, | ||
debug: true, | ||
enableDelegation: true | ||
|
||
// Custom RPC | ||
// ... NOT GIVEN ... | ||
}; | ||
|
||
/** | ||
* Hardhat configuration | ||
*/ | ||
const config: HardhatUserConfig = { | ||
solidity: '0.8.17', | ||
networks: { | ||
vechain_testnet: vechainTestNetwork | ||
}, | ||
|
||
/** | ||
* @note: here we set vechain_testnet as the default network to simulate a command like this: | ||
* | ||
* ```sh | ||
* npx hardhat --network vechain_testnet <command> | ||
* ``` | ||
*/ | ||
defaultNetwork: 'vechain_testnet' | ||
}; | ||
|
||
export default config; |
Oops, something went wrong.
07f8f63
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test Coverage
Summary