lint && fix test

pull/4817/head^2
yann300 5 months ago committed by Aniket
parent 33c126b8d8
commit e2a30eded8
  1. 20
      libs/remix-simulator/src/methods/accounts.ts
  2. 11
      libs/remix-simulator/test/accounts.ts

@ -124,45 +124,45 @@ export class Web3Accounts {
eth_signTypedData_v4 (payload, cb) { eth_signTypedData_v4 (payload, cb) {
const address: string = payload.params[0] const address: string = payload.params[0]
const typedData: TypedMessage<MessageTypes> = payload.params[1] const typedData: TypedMessage<MessageTypes> = payload.params[1]
try { try {
if (this.accounts[toChecksumAddress(address)] == null) { if (this.accounts[toChecksumAddress(address)] == null) {
throw new Error("cannot sign data; no private key"); throw new Error("cannot sign data; no private key");
} }
if (typeof typedData === "string") { if (typeof typedData === "string") {
throw new Error("cannot sign data; string sent, expected object"); throw new Error("cannot sign data; string sent, expected object");
} }
if (!typedData.types) { if (!typedData.types) {
throw new Error("cannot sign data; types missing"); throw new Error("cannot sign data; types missing");
} }
if (!typedData.types.EIP712Domain) { if (!typedData.types.EIP712Domain) {
throw new Error("cannot sign data; EIP712Domain definition missing"); throw new Error("cannot sign data; EIP712Domain definition missing");
} }
if (!typedData.domain) { if (!typedData.domain) {
throw new Error("cannot sign data; domain missing"); throw new Error("cannot sign data; domain missing");
} }
if (!typedData.primaryType) { if (!typedData.primaryType) {
throw new Error("cannot sign data; primaryType missing"); throw new Error("cannot sign data; primaryType missing");
} }
if (!typedData.message) { if (!typedData.message) {
throw new Error("cannot sign data; message missing"); throw new Error("cannot sign data; message missing");
} }
const ret = signTypedData({ const ret = signTypedData({
privateKey: Buffer.from(this.accounts[toChecksumAddress(address)].privateKey), privateKey: Buffer.from(this.accounts[toChecksumAddress(address)].privateKey),
data: typedData, data: typedData,
version: SignTypedDataVersion.V4 version: SignTypedDataVersion.V4
}) })
cb(null, ret) cb(null, ret)
} catch (e) { } catch (e) {
cb(e.message) cb(e.message)
} }
} }
} }

@ -68,13 +68,14 @@ describe('Accounts', () => {
], ],
}, },
}; };
web3.currentProvider.sendAsync({ const result = await web3.currentProvider.sendAsync({
method: 'eth_signTypedData', method: 'eth_signTypedData',
params: [accounts[0], typedData] params: [accounts[0], typedData],
}, function (err, result) { id: 0,
console.log(err, result) jsonrpc: '2.0'
assert.equal(result.result, '0xe4ee76332af49888d86a09eea70dfd5b9a7085e2e013cbba4c0cb41766eab69a6216f18b80d9277241ce35b74b6c46add36d5189eb5a94a258f076dfc4dd21161b')
}) })
console.log(result)
assert.equal(result, '0xe4ee76332af49888d86a09eea70dfd5b9a7085e2e013cbba4c0cb41766eab69a6216f18b80d9277241ce35b74b6c46add36d5189eb5a94a258f076dfc4dd21161b')
}) })
}) })
}) })

Loading…
Cancel
Save