-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix: translateAddress should not rely on PublicKey constructor nam #1138
Merged
paul-schaaf
merged 5 commits into
coral-xyz:master
from
0xCryptoSheik:fix/translate-address-no-constructor-name
Dec 15, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7712004
ts: fix translateAddress should not rely on PublicKey constructor name
0xCryptoSheik e4b28a9
Merge branch 'master' into fix/translate-address-no-constructor-name
paul-schaaf 82a338d
docs: update changelog
paul-schaaf 5ae4181
ts: adjust translateAddress to allow PublicKeys to pass through
paul-schaaf 98e0fb0
tests: update lock file
paul-schaaf 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 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 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 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 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,56 @@ | ||
import BN from "bn.js"; | ||
import bs58 from "bs58"; | ||
import { PublicKey } from "@solana/web3.js"; | ||
|
||
import { translateAddress } from "../src/program/common"; | ||
|
||
describe("program/common", () => { | ||
describe("translateAddress", () => { | ||
it("should accept a valid string address", () => { | ||
const address = "11111111111111111111111111111111"; | ||
|
||
const func = () => translateAddress(address); | ||
expect(func).not.toThrow(); | ||
|
||
const output = func(); | ||
expect(output).toBeInstanceOf(PublicKey); | ||
expect(new PublicKey(address).equals(output)).toBeTruthy(); | ||
}); | ||
|
||
it("should accept a PublicKey address", () => { | ||
const publicKey = new PublicKey("11111111111111111111111111111111"); | ||
|
||
const func = () => translateAddress(publicKey); | ||
expect(func).not.toThrow(); | ||
|
||
const output = func(); | ||
expect(output).toBeInstanceOf(PublicKey); | ||
expect(new PublicKey(publicKey).equals(output)).toBe(true); | ||
}); | ||
|
||
it("should accept an object with a PublicKey shape { _bn }", () => { | ||
const obj = ({ | ||
_bn: new BN(bs58.decode("11111111111111111111111111111111")), | ||
} as any) as PublicKey; | ||
const func = () => translateAddress(obj); | ||
|
||
expect(func).not.toThrow(); | ||
const output = func(); | ||
|
||
expect(output).toBeInstanceOf(PublicKey); | ||
expect(new PublicKey(obj).equals(output)).toBe(true); | ||
}); | ||
|
||
it("should not accept an invalid string address", () => { | ||
const invalid = "invalid"; | ||
const func = () => translateAddress(invalid); | ||
expect(func).toThrow(); | ||
}); | ||
|
||
it("should not accept an invalid object", () => { | ||
const invalid = {} as PublicKey; | ||
const func = () => translateAddress(invalid); | ||
expect(func).toThrow(); | ||
}); | ||
}); | ||
}); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for these tests!