[web3] Fix Arguments to Match Web3 1.0 Docs (#28807)

* Update utils.soliditySha3 argument types per web3@1.0 documentation

See https://web3js.readthedocs.io/en/1.0/web3-utils.html#soliditysha3
for details

* Add `position` to getStorageAt

See https://web3js.readthedocs.io/en/1.0/web3-eth.html#getstorageat

* Add web3 getStorageAt and soliditySha3 tests

* Reuse contractAddress variable in web3 test
This commit is contained in:
Mike Seese
2018-09-13 15:53:31 -04:00
committed by Ryan Cavanaugh
parent 89bf834e02
commit 0e2aeeb4d0
3 changed files with 21 additions and 2 deletions

View File

@@ -125,6 +125,7 @@ export default interface Eth {
getProtocolVersion(cb?: Callback<string>): Promise<string>;
getStorageAt(
address: string,
position: number | BigNumber,
defaultBlock?: BlockType,
cb?: Callback<string>
): Promise<string>;

16
types/web3/utils.d.ts vendored
View File

@@ -29,6 +29,20 @@ type Unit =
| "mether"
| "gether"
| "tether";
type Mixed =
| string
| number
| BigNumber
| {
type: string;
value: string;
}
| {
t: string;
v: string;
};
export default interface Utils {
BN: BigNumber; // TODO only static-definition
isBN(any: any): boolean;
@@ -62,7 +76,7 @@ export default interface Utils {
val4?: string,
val5?: string
): string;
soliditySha3(val: string): string;
soliditySha3(...val: Mixed[]): string;
randomHex(bytes: number): string;
stringToHex(val: string): string;
toAscii(hex: string): string;

View File

@@ -5,9 +5,11 @@ const myProvider = new web3.providers.HttpProvider("http://localhost:5454");
web3.setProvider(myProvider);
web3.eth.setProvider(myProvider);
const contractAddress = "0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe";
const myContract = new web3.eth.Contract(
[],
"0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe",
contractAddress,
{
from: "0x1234567890123456789012345678901234567891",
gasPrice: "20000000000"
@@ -22,3 +24,5 @@ const weiStr: string = web3.utils.toWei("100", "gwei");
const weiBn: BigNumber = web3.utils.toWei(web3.utils.toBN("1"));
const rndHex: string = Web3.utils.randomHex(10);
const shhPromise: Promise<string> = web3.shh.generateSymKeyFromPassword("xyz");
const storage: Promise<string> = web3.eth.getStorageAt(contractAddress, 0);
const sha3: string = web3.utils.soliditySha3(0, 1, "abc");