Skip to content

Commit

Permalink
Add checksum to constants in isValidProtocol (#864) (#865)
Browse files Browse the repository at this point in the history
* Add checksum to constants in isValidProtocol (#864)

* Increase package version

* Add unit tests

---------

Co-authored-by: Reagan <[email protected]>
  • Loading branch information
JoshuaSchmidt-OpenSea and reaganchisholm authored Mar 7, 2023
1 parent df72323 commit a24cc4f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
30 changes: 30 additions & 0 deletions src/__tests__/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -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))
);
});
});
2 changes: 1 addition & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

0 comments on commit a24cc4f

Please sign in to comment.