diff --git a/package-lock.json b/package-lock.json index 0a32b9b5b..070ad986f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "opensea-js", - "version": "4.0.15", + "version": "4.0.19", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "opensea-js", - "version": "4.0.15", + "version": "4.0.19", "license": "MIT", "dependencies": { "@opensea/seaport-js": "^1.0.10", diff --git a/package.json b/package.json index c70faf44f..6db0a6a87 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "opensea-js", - "version": "4.0.18", + "version": "4.0.19", "description": "JavaScript SDK for the OpenSea marketplace. Let users buy or sell crypto collectibles and other cryptogoods, all on your own site!", "license": "MIT", "author": "OpenSea Developers", diff --git a/src/__tests__/utils/utils.ts b/src/__tests__/utils/utils.ts new file mode 100644 index 000000000..5a0919afc --- /dev/null +++ b/src/__tests__/utils/utils.ts @@ -0,0 +1,30 @@ +import { + CROSS_CHAIN_SEAPORT_ADDRESS, + CROSS_CHAIN_SEAPORT_V1_4_ADDRESS, +} from "@opensea/seaport-js/lib/constants"; +import { assert } from "chai"; +import { suite, test } from "mocha"; +import Web3 from "web3"; +import { isValidProtocol } from "../../utils/utils"; + +suite("Utils: utils", () => { + test("isValidProtocol works with all forms of address", async () => { + const seaport_v1_1 = CROSS_CHAIN_SEAPORT_ADDRESS; + const seaport_v_1_4 = CROSS_CHAIN_SEAPORT_V1_4_ADDRESS; + const randomAddress = "0x1F7Cf51573Bf5270323a395F0bb5Fd3c3a4DB867"; + + assert.isTrue(isValidProtocol(seaport_v1_1)); + assert.isTrue(isValidProtocol(seaport_v_1_4)); + assert.isFalse(isValidProtocol(randomAddress)); + + assert.isTrue(isValidProtocol(seaport_v1_1.toLowerCase())); + assert.isTrue(isValidProtocol(seaport_v_1_4.toLowerCase())); + assert.isFalse(isValidProtocol(randomAddress.toLowerCase())); + + assert.isTrue(isValidProtocol(Web3.utils.toChecksumAddress(seaport_v1_1))); + assert.isTrue(isValidProtocol(Web3.utils.toChecksumAddress(seaport_v_1_4))); + assert.isFalse( + isValidProtocol(Web3.utils.toChecksumAddress(randomAddress)) + ); + }); +}); diff --git a/src/utils/utils.ts b/src/utils/utils.ts index a96289a48..f2b95b3cf 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1145,6 +1145,6 @@ export const isValidProtocol = (protocolAddress: string): boolean => { const validProtocolAddresses = [ CROSS_CHAIN_SEAPORT_ADDRESS, CROSS_CHAIN_SEAPORT_V1_4_ADDRESS, - ]; + ].map((address) => Web3.utils.toChecksumAddress(address)); return validProtocolAddresses.includes(checkSumAddress); };