Skip to content

Commit

Permalink
chore: add chai-matchers tests and bump dependencies v5 (#716)
Browse files Browse the repository at this point in the history
* chore: add chai-matchers tests and bump dependencies
  • Loading branch information
nikola-bozin-txfusion authored Feb 1, 2024
1 parent 2db3a89 commit 33e6e20
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 59 deletions.
12 changes: 12 additions & 0 deletions packages/hardhat-zksync-chai-matchers/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,15 @@ export class ZkSyncChaiMatchersPluginError extends HardhatPluginError {
super(PLUGIN_NAME, message, parentError);
}
}

export class ZkSyncChaiMatchersPluginDefaultError extends HardhatPluginError {
constructor(message: string) {
super(PLUGIN_NAME, message);
}
}

export class ZkSyncChaiMatchersPluginAssertionError extends HardhatPluginError {
constructor(message: string) {
super(PLUGIN_NAME, `Assertion error: ${message}`);
}
}
7 changes: 7 additions & 0 deletions packages/hardhat-zksync-chai-matchers/src/internal/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ZkSyncChaiMatchersPluginDefaultError } from '../errors';

export function assertIsNotNull<T>(value: T, valueName: string): asserts value is Exclude<T, null> {
if (value === null) {
throw new ZkSyncChaiMatchersPluginDefaultError(`${valueName} should not be null`);
}
}
83 changes: 83 additions & 0 deletions packages/hardhat-zksync-chai-matchers/test/reverted/misc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { expect } from "chai";
import { decodeReturnData, getReturnDataFromError } from "../../src/internal/reverted/utils";
import { getAddressOf, isWalletOrContract } from "../../src/internal/misc/account";
import * as zk from 'zksync-ethers';
import { assertIsNotNull } from "../../src/internal/utils";

class TestError extends Error {
data?: any;

constructor(message: string, data?: any) {
super(message);
this.data = data;
}
}

describe('Miscellaneous tests', function () {
it('fails to decode return data', async function () {
try {
const ERROR_STRING_PREFIX = '0x08c379a0';
const malformedReturnData = ERROR_STRING_PREFIX + 'ThisIsNotValidEncodedData';
decodeReturnData(malformedReturnData);
} catch (e: any) {
expect(e.message.includes("There was an error decoding"), "Should have fail to decode return data");
}
})


it('fails because its null', async function () {
const valueName = 'test-case';
try {
assertIsNotNull(null, valueName)
} catch (e: any) {
expect(e.message.includes(`${valueName} should not be null`), "Should have thrown an error");
}
})


it('should throw ZkSyncChaiMatchersPluginAssertionError for invalid account input', async () => {
const invalidAccount = 12345;
try {
await getAddressOf(invalidAccount as any);
throw new Error('Expected error was not thrown');
} catch (e: any) {
expect(e.message).to.include(`account.getAddress is not a function`);
}
});

it('returns true for a zkSync wallet', async () => {
const testMnemonic = 'stuff slice staff easily soup parent arm payment cotton trade scatter struggle';
const zkWallet = zk.Wallet.fromMnemonic(testMnemonic);

const result = isWalletOrContract(zkWallet);
expect(result).to.be.true;
});

it('returns false for a non-wallet/non-contract account', async () => {
const nonWalletAccount = {} as any;

const result = isWalletOrContract(nonWalletAccount);
expect(result).to.be.false;
});

it('should throw the original error when returnData is undefined', async () => {
const error = new TestError('Test error');
try {
getReturnDataFromError(error);
throw new Error('Expected error was not thrown');
} catch (e: any) {
expect(e.message.includes('Test error'), "Should have included test error");
}
});

it('should throw the original error when returnData is not a string', async () => {
const error = new TestError('Test error with wrong data', { data: 123 });
try {
getReturnDataFromError(error);
throw new Error('Expected error was not thrown');
} catch (e: any) {
expect(e.message.includes('Test error with wrong data'), "Should have included test error");
}
});

})
2 changes: 1 addition & 1 deletion packages/hardhat-zksync-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"prettier": "2.5.1",
"proxyquire": "^2.1.3",
"rimraf": "^3.0.2",
"sinon": "^16.0.0",
"sinon": "^17.0.1",
"sinon-chai": "^3.7.0",
"ts-node": "^10.6.0",
"typescript": "^4.6.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat-zksync-verify-vyper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"mocha": "^9.2.1",
"prettier": "2.5.1",
"rimraf": "^3.0.2",
"sinon": "^15.0.1",
"sinon": "^17.0.1",
"ts-node": "^10.6.0",
"typescript": "^4.6.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat-zksync-verify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"debug": "^4.1.1",
"@openzeppelin/contracts": "^4.9.2",
"sinon-chai": "^3.7.0",
"sinon": "^16.0.0"
"sinon": "^17.0.1"
},
"devDependencies": {
"@nomicfoundation/hardhat-verify": "^2.0.0",
Expand Down
126 changes: 70 additions & 56 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@
semver "^7.5.1"

"@matterlabs/hardhat-zksync-upgradable@link:packages/hardhat-zksync-upgradable":
version "0.2.0"
version "0.2.1"
dependencies:
"@matterlabs/hardhat-zksync-deploy" "^0.7.0"
"@matterlabs/hardhat-zksync-solc" "^1.0.5"
Expand All @@ -844,8 +844,20 @@
dockerode "^3.3.4"
solidity-ast "npm:[email protected]"

"@matterlabs/hardhat-zksync-verify@link:packages/hardhat-zksync-verify":
"@matterlabs/hardhat-zksync-verify@^0.4.0":
version "0.4.0"
resolved "https://registry.yarnpkg.com/@matterlabs/hardhat-zksync-verify/-/hardhat-zksync-verify-0.4.0.tgz#f812c19950022fc36728f3796f6bdae5633e2fcd"
integrity sha512-GPZmAumFl3ZMPKbECX7Qw8CriwZKWd1DlCRhoG/6YYc6mFy4+MXkF1XsHLMs5r34N+GDOfbVZVMeftIlJC96Kg==
dependencies:
"@matterlabs/hardhat-zksync-solc" "^1.0.5"
"@nomicfoundation/hardhat-verify" "^1.0.2"
axios "^1.4.0"
chalk "4.1.2"
dockerode "^3.3.4"
zksync-ethers "^5.0.0"

"@matterlabs/hardhat-zksync-verify@link:packages/hardhat-zksync-verify":
version "0.5.0"
dependencies:
"@ethersproject/abi" "^5.1.2"
"@ethersproject/address" "5.7.0"
Expand All @@ -858,7 +870,7 @@
chalk "4.1.2"
debug "^4.1.1"
hardhat "^2.14.0"
sinon "^16.0.0"
sinon "^17.0.1"
sinon-chai "^3.7.0"
zksync-ethers "^5.0.0"

Expand Down Expand Up @@ -1077,6 +1089,21 @@
deep-eql "^4.0.1"
ordinal "^1.0.3"

"@nomicfoundation/hardhat-verify@^1.0.2":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@nomicfoundation/hardhat-verify/-/hardhat-verify-1.1.1.tgz#6a433d777ce0172d1f0edf7f2d3e1df14b3ecfc1"
integrity sha512-9QsTYD7pcZaQFEA3tBb/D/oCStYDiEVDN7Dxeo/4SCyHRSm86APypxxdOMEPlGmXsAvd+p1j/dTODcpxb8aztA==
dependencies:
"@ethersproject/abi" "^5.1.2"
"@ethersproject/address" "^5.0.2"
cbor "^8.1.0"
chalk "^2.4.2"
debug "^4.1.1"
lodash.clonedeep "^4.5.0"
semver "^6.3.0"
table "^6.8.0"
undici "^5.14.0"

"@nomicfoundation/hardhat-verify@^2.0.0":
version "2.0.3"
resolved "https://registry.yarnpkg.com/@nomicfoundation/hardhat-verify/-/hardhat-verify-2.0.3.tgz#173557f8cfa53c8c9da23a326f54d24fe459ae68"
Expand Down Expand Up @@ -1358,13 +1385,6 @@
"@sentry/types" "5.30.0"
tslib "^1.9.3"

"@sinonjs/commons@^1.7.0":
version "1.8.6"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.8.6.tgz#80c516a4dc264c2a69115e7578d62581ff455ed9"
integrity sha512-Ky+XkAkqPZSm3NLBeUng77EBQl3cmeJhITaGHdYH8kjVB+aun3S4XBRti2zt17mtt0mIUDiNxYeoJm6drVvBJQ==
dependencies:
type-detect "4.0.8"

"@sinonjs/commons@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-2.0.0.tgz#fd4ca5b063554307e8327b4564bd56d3b73924a3"
Expand All @@ -1379,35 +1399,19 @@
dependencies:
type-detect "4.0.8"

"@sinonjs/[email protected]":
version "10.0.2"
resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-10.0.2.tgz#d10549ed1f423d80639c528b6c7f5a1017747d0c"
integrity sha512-SwUDyjWnah1AaNl7kxsa7cfLhlTYoiyhDAIgyh+El30YvXs/o7OLXpYH88Zdhyx9JExKrmHDJ+10bwIcY80Jmw==
dependencies:
"@sinonjs/commons" "^2.0.0"

"@sinonjs/fake-timers@^10.0.2", "@sinonjs/fake-timers@^10.3.0":
version "10.3.0"
resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-10.3.0.tgz#55fdff1ecab9f354019129daf4df0dd4d923ea66"
integrity sha512-V4BG07kuYSUkTCSBHG8G8TNhM+F19jXFWnQtzj+we8DrkpSBCee9Z3Ms8yiGer/dlmhe35/Xdgyo3/0rQKg7YA==
dependencies:
"@sinonjs/commons" "^3.0.0"

"@sinonjs/fake-timers@^7.0.4":
version "7.1.2"
resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-7.1.2.tgz#2524eae70c4910edccf99b2f4e6efc5894aff7b5"
integrity sha512-iQADsW4LBMISqZ6Ci1dupJL9pprqwcVFTcOsEmQOEhW+KLCVn/Y4Jrvg2k19fIHCp+iFprriYPTdRcQR8NbUPg==
"@sinonjs/fake-timers@^11.2.2":
version "11.2.2"
resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-11.2.2.tgz#50063cc3574f4a27bd8453180a04171c85cc9699"
integrity sha512-G2piCSxQ7oWOxwGSAyFHfPIsyeJGXYtc6mFbnFA+kRXkiEnTl8c/8jul2S329iFBnDI9HGoeWWAZvuvOkZccgw==
dependencies:
"@sinonjs/commons" "^1.7.0"

"@sinonjs/samsam@^7.0.1":
version "7.0.1"
resolved "https://registry.yarnpkg.com/@sinonjs/samsam/-/samsam-7.0.1.tgz#5b5fa31c554636f78308439d220986b9523fc51f"
integrity sha512-zsAk2Jkiq89mhZovB2LLOdTCxJF4hqqTToGP0ASWlhp4I1hqOjcfmZGafXntCN7MDC6yySH0mFHrYtHceOeLmw==
dependencies:
"@sinonjs/commons" "^2.0.0"
lodash.get "^4.4.2"
type-detect "^4.0.8"
"@sinonjs/commons" "^3.0.0"

"@sinonjs/samsam@^8.0.0":
version "8.0.0"
Expand All @@ -1418,7 +1422,7 @@
lodash.get "^4.4.2"
type-detect "^4.0.8"

"@sinonjs/text-encoding@^0.7.1":
"@sinonjs/text-encoding@^0.7.1", "@sinonjs/text-encoding@^0.7.2":
version "0.7.2"
resolved "https://registry.yarnpkg.com/@sinonjs/text-encoding/-/text-encoding-0.7.2.tgz#5981a8db18b56ba38ef0efb7d995b12aa7b51918"
integrity sha512-sXXKG+uL9IrKqViTtao2Ws6dy0znu9sOaP1di/jKGW1M6VssO8vlpXCQcpZ+jisQ1tTFAC5Jo/EOzFbggBagFQ==
Expand Down Expand Up @@ -3078,7 +3082,7 @@ diff@^4.0.1:
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==

diff@^5.0.0, diff@^5.1.0:
diff@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-5.1.0.tgz#bc52d298c5ea8df9194800224445ed43ffc87e40"
integrity sha512-D+mk+qE8VC/PAUrlAU34N+VfXev0ghe5ywmpqrawphmVZc1bEfn56uo9qpyGp1p4xpzOHkSW4ztBd6L7Xx4ACw==
Expand Down Expand Up @@ -4965,6 +4969,11 @@ just-extend@^4.0.2:
resolved "https://registry.yarnpkg.com/just-extend/-/just-extend-4.2.1.tgz#ef5e589afb61e5d66b24eca749409a8939a8c744"
integrity sha512-g3UB796vUFIY90VIv/WX3L2c8CS2MdWUww3CNrYmqza1Fg0DURc2K/O4YrnklBdQarSJ/y8JnJYDGc+1iumQjg==

just-extend@^6.2.0:
version "6.2.0"
resolved "https://registry.yarnpkg.com/just-extend/-/just-extend-6.2.0.tgz#b816abfb3d67ee860482e7401564672558163947"
integrity sha512-cYofQu2Xpom82S6qD778jBDpwvvy39s1l/hrYij2u9AMdQcGRpaBu6kY4mVhuno5kJVi1DAz4aiphA2WI1/OAw==

keccak@^3.0.0, keccak@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/keccak/-/keccak-3.0.2.tgz#4c2c6e8c54e04f2670ee49fa734eb9da152206e0"
Expand Down Expand Up @@ -5479,17 +5488,6 @@ nice-try@^1.0.4:
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==

nise@^5.1.2:
version "5.1.3"
resolved "https://registry.yarnpkg.com/nise/-/nise-5.1.3.tgz#f46197e5f60ae9a96401b602bd9d8239b1ee8656"
integrity sha512-U597iWTTBBYIV72986jyU382/MMZ70ApWcRmkoF1AZ75bpqOtI3Gugv/6+0jLgoDOabmcSwYBkSSAWIp1eA5cg==
dependencies:
"@sinonjs/commons" "^2.0.0"
"@sinonjs/fake-timers" "^7.0.4"
"@sinonjs/text-encoding" "^0.7.1"
just-extend "^4.0.2"
path-to-regexp "^1.7.0"

nise@^5.1.4:
version "5.1.4"
resolved "https://registry.yarnpkg.com/nise/-/nise-5.1.4.tgz#491ce7e7307d4ec546f5a659b2efe94a18b4bbc0"
Expand All @@ -5501,6 +5499,17 @@ nise@^5.1.4:
just-extend "^4.0.2"
path-to-regexp "^1.7.0"

nise@^5.1.5:
version "5.1.7"
resolved "https://registry.yarnpkg.com/nise/-/nise-5.1.7.tgz#03ca96539efb306612eb60a8c5d6beeb208e27e5"
integrity sha512-wWtNUhkT7k58uvWTB/Gy26eA/EJKtPZFVAhEilN5UYVmmGRYOURbejRUyKm0Uu9XVEW7K5nBOZfR8VMB4QR2RQ==
dependencies:
"@sinonjs/commons" "^3.0.0"
"@sinonjs/fake-timers" "^11.2.2"
"@sinonjs/text-encoding" "^0.7.2"
just-extend "^6.2.0"
path-to-regexp "^6.2.1"

node-addon-api@^2.0.0:
version "2.0.2"
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-2.0.2.tgz#432cfa82962ce494b132e9d72a15b29f71ff5d32"
Expand Down Expand Up @@ -5818,6 +5827,11 @@ path-to-regexp@^1.7.0:
dependencies:
isarray "0.0.1"

path-to-regexp@^6.2.1:
version "6.2.1"
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-6.2.1.tgz#d54934d6798eb9e5ef14e7af7962c945906918e5"
integrity sha512-JLyh7xT1kizaEvcaXOQwOc2/Yhw6KZOvPf1S8401UyLk86CU79LN3vl7ztXGm/pZ+YjoyAJ4rxmHwbkBXJX+yw==

path-type@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/path-type/-/path-type-3.0.0.tgz#cef31dc8e0a1a3bb0d105c0cd97cf3bf47f4e36f"
Expand Down Expand Up @@ -6410,18 +6424,6 @@ sinon-chai@^3.7.0:
resolved "https://registry.yarnpkg.com/sinon-chai/-/sinon-chai-3.7.0.tgz#cfb7dec1c50990ed18c153f1840721cf13139783"
integrity sha512-mf5NURdUaSdnatJx3uhoBOrY9dtL19fiOtAdT1Azxg3+lNJFiuN0uzaU3xX1LeAfL17kHQhTAJgpsfhbMJMY2g==

sinon@^15.0.1:
version "15.0.1"
resolved "https://registry.yarnpkg.com/sinon/-/sinon-15.0.1.tgz#ce062611a0b131892e2c18f03055b8eb6e8dc234"
integrity sha512-PZXKc08f/wcA/BMRGBze2Wmw50CWPiAH3E21EOi4B49vJ616vW4DQh4fQrqsYox2aNR/N3kCqLuB0PwwOucQrg==
dependencies:
"@sinonjs/commons" "^2.0.0"
"@sinonjs/fake-timers" "10.0.2"
"@sinonjs/samsam" "^7.0.1"
diff "^5.0.0"
nise "^5.1.2"
supports-color "^7.2.0"

sinon@^16.0.0:
version "16.0.0"
resolved "https://registry.yarnpkg.com/sinon/-/sinon-16.0.0.tgz#06da4e63624b946c9d7e67cce21c2f67f40f23a9"
Expand All @@ -6434,6 +6436,18 @@ sinon@^16.0.0:
nise "^5.1.4"
supports-color "^7.2.0"

sinon@^17.0.1:
version "17.0.1"
resolved "https://registry.yarnpkg.com/sinon/-/sinon-17.0.1.tgz#26b8ef719261bf8df43f925924cccc96748e407a"
integrity sha512-wmwE19Lie0MLT+ZYNpDymasPHUKTaZHUH/pKEubRXIzySv9Atnlw+BUMGCzWgV7b7wO+Hw6f1TEOr0IUnmU8/g==
dependencies:
"@sinonjs/commons" "^3.0.0"
"@sinonjs/fake-timers" "^11.2.2"
"@sinonjs/samsam" "^8.0.0"
diff "^5.1.0"
nise "^5.1.5"
supports-color "^7.2.0"

slash@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55"
Expand Down

0 comments on commit 33e6e20

Please sign in to comment.