-
Couldn't load subscription status.
- Fork 0
fix(SDK): Fix missing address on pageview and custom events #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5442186
fix(SDK): Fix missing address on pageview and custom events
yosriady 59ac767
PR comment
yosriady fc53c7c
Fix
yosriady 016991e
Refactor
yosriady e58efc8
Refactor
yosriady 63a539d
Refactor
yosriady d384eab
Refactor
yosriady 8f9d283
Refactor
yosriady ae9cbd7
Refactor
yosriady 964262e
Remove unused import
yosriady File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| import { describe, it } from "mocha"; | ||
| import { expect } from "chai"; | ||
| import { toChecksumAddress } from "../../../src/utils"; | ||
| import { isValidAddress, getValidAddress } from "../../../src/utils/address"; | ||
| import { isAddress } from "../../../src/validators"; | ||
|
|
||
| describe("Address handling bug fix", () => { | ||
| describe("toChecksumAddress function", () => { | ||
| it("should throw error when empty string is passed", () => { | ||
| expect(() => toChecksumAddress("")).to.throw("Invalid address "); | ||
| }); | ||
|
|
||
| it("should throw error when undefined is passed", () => { | ||
| expect(() => toChecksumAddress(undefined as any)).to.throw("Invalid address undefined"); | ||
| }); | ||
|
|
||
| it("should throw error when null is passed", () => { | ||
| expect(() => toChecksumAddress(null as any)).to.throw("Invalid address null"); | ||
| }); | ||
|
|
||
| it("should handle valid addresses correctly", () => { | ||
| const validAddress = "0x1095bBe769fDab716A823d0f7149CAD713d20A13"; | ||
| expect(() => toChecksumAddress(validAddress)).to.not.throw(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("isValidAddress helper function", () => { | ||
| it("should correctly identify empty strings as invalid", () => { | ||
| const testAddress: string = ""; | ||
| expect(isValidAddress(testAddress)).to.be.false; | ||
| }); | ||
|
|
||
| it("should correctly identify undefined as invalid", () => { | ||
| const testAddress: string | undefined = undefined; | ||
| expect(isValidAddress(testAddress)).to.be.false; | ||
| }); | ||
|
|
||
| it("should correctly identify null as invalid", () => { | ||
| const testAddress: string | null = null; | ||
| expect(isValidAddress(testAddress)).to.be.false; | ||
| }); | ||
|
|
||
| it("should correctly identify whitespace-only strings as invalid", () => { | ||
| const testAddress: string = " "; | ||
| expect(isValidAddress(testAddress)).to.be.false; | ||
| }); | ||
|
|
||
| it("should correctly identify valid addresses", () => { | ||
| const testAddress: string = "0x1095bBe769fDab716A823d0f7149CAD713d20A13"; | ||
| expect(isValidAddress(testAddress)).to.be.true; | ||
| }); | ||
|
|
||
| it("should correctly identify non-empty strings as valid", () => { | ||
| const testAddress: string = "0x1234567890123456789012345678901234567890"; | ||
| expect(isValidAddress(testAddress)).to.be.true; | ||
| }); | ||
|
|
||
| it("should correctly identify addresses with leading/trailing whitespace as valid", () => { | ||
| const testAddress: string = " 0x1095bBe769fDab716A823d0f7149CAD713d20A13 "; | ||
| expect(isValidAddress(testAddress)).to.be.true; | ||
| }); | ||
| }); | ||
|
|
||
| describe("getValidAddress function", () => { | ||
| it("should return trimmed valid address", () => { | ||
| const testAddress = " 0x1095bBe769fDab716A823d0f7149CAD713d20A13 "; | ||
| const result = getValidAddress(testAddress); | ||
| expect(result).to.equal("0x1095bBe769fDab716A823d0f7149CAD713d20A13"); | ||
| }); | ||
|
|
||
| it("should return null for invalid addresses", () => { | ||
| const testAddress = "invalid-address"; | ||
| const result = getValidAddress(testAddress); | ||
| expect(result).to.be.null; | ||
| }); | ||
|
|
||
| it("should return null for empty strings", () => { | ||
| const testAddress = ""; | ||
| const result = getValidAddress(testAddress); | ||
| expect(result).to.be.null; | ||
| }); | ||
|
|
||
| it("should return null for whitespace-only strings", () => { | ||
| const testAddress = " "; | ||
| const result = getValidAddress(testAddress); | ||
| expect(result).to.be.null; | ||
| }); | ||
| }); | ||
|
|
||
| describe("Comparison between isValidAddress and isAddress", () => { | ||
| it("should handle invalid addresses differently", () => { | ||
| const invalidAddresses = [ | ||
| "", // empty string | ||
| " ", // whitespace only | ||
| "not-an-address", // invalid format | ||
| "0x123", // too short | ||
| "0x1234567890123456789012345678901234567890123456789012345678901234567890", // too long | ||
| ]; | ||
|
|
||
| invalidAddresses.forEach(address => { | ||
| // isValidAddress should return false for all invalid addresses | ||
| expect(isValidAddress(address)).to.be.false; | ||
|
|
||
| // isAddress should also return false for invalid addresses | ||
| expect(isAddress(address)).to.be.false; | ||
| }); | ||
| }); | ||
|
|
||
| it("should handle valid addresses consistently", () => { | ||
| const validAddresses = [ | ||
| "0x1095bBe769fDab716A823d0f7149CAD713d20A13", | ||
| "0x1234567890123456789012345678901234567890", | ||
| "0x1095bBe769fDab716A823d0f7149CAD713d20A13 ", // with trailing whitespace | ||
| " 0x1095bBe769fDab716A823d0f7149CAD713d20A13", // with leading whitespace | ||
| ]; | ||
|
|
||
| validAddresses.forEach(address => { | ||
| // isValidAddress should return true for valid addresses (after trimming) | ||
| expect(isValidAddress(address)).to.be.true; | ||
|
|
||
| // isAddress should return true for valid addresses (after trimming) | ||
| expect(isAddress(address.trim())).to.be.true; | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Whitespace handling bug fix", () => { | ||
| it("should handle addresses with whitespace without throwing errors", () => { | ||
| const addressWithWhitespace = " 0x1095bBe769fDab716A823d0f7149CAD713d20A13 "; | ||
|
|
||
| // This should not throw an error | ||
| expect(() => { | ||
| const validAddress = getValidAddress(addressWithWhitespace); | ||
| if (validAddress) { | ||
| toChecksumAddress(validAddress); | ||
| } | ||
| }).to.not.throw(); | ||
| }); | ||
|
|
||
| it("should properly trim addresses before validation", () => { | ||
| const addressWithWhitespace = " 0x1095bBe769fDab716A823d0f7149CAD713d20A13 "; | ||
| const trimmedAddress = "0x1095bBe769fDab716A823d0f7149CAD713d20A13"; | ||
|
|
||
| expect(isValidAddress(addressWithWhitespace)).to.be.true; | ||
| expect(getValidAddress(addressWithWhitespace)).to.equal(trimmedAddress); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.