-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#fix appName can be empty string (#1244)
* merged commits * test
- Loading branch information
1 parent
ac1990c
commit 1b3c781
Showing
4 changed files
with
194 additions
and
125 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,122 +1,68 @@ | ||
import { CoinbaseWalletProvider } from './CoinbaseWalletProvider'; | ||
import { CoinbaseWalletSDK } from './CoinbaseWalletSDK'; | ||
import { ProviderInterface } from ':core/provider/interface'; | ||
import { getFavicon } from ':core/type/util'; | ||
import { getCoinbaseInjectedProvider } from ':util/provider'; | ||
|
||
const window = globalThis as any; | ||
jest.mock(':core/type/util'); | ||
jest.mock(':util/provider'); | ||
jest.mock('./CoinbaseWalletProvider'); | ||
|
||
describe('CoinbaseWalletSDK', () => { | ||
describe('public methods', () => { | ||
let coinbaseWalletSDK2: CoinbaseWalletSDK; | ||
beforeEach(() => { | ||
coinbaseWalletSDK2 = new CoinbaseWalletSDK({ | ||
appName: 'Test', | ||
appLogoUrl: 'http://coinbase.com/wallet-logo.png', | ||
}); | ||
}); | ||
|
||
describe('sdk', () => { | ||
test('@makeWeb3Provider', () => { | ||
expect(coinbaseWalletSDK2.makeWeb3Provider()).toBeInstanceOf(CoinbaseWalletProvider); | ||
}); | ||
|
||
test('@getCoinbaseWalletLogo', () => { | ||
let svgUri; | ||
|
||
svgUri = coinbaseWalletSDK2.getCoinbaseWalletLogo('standard'); | ||
expect(svgUri).toContain("viewBox='0 0 1024 1024'"); | ||
|
||
svgUri = coinbaseWalletSDK2.getCoinbaseWalletLogo('circle'); | ||
expect(svgUri).toContain("viewBox='0 0 999.81 999.81'"); | ||
|
||
svgUri = coinbaseWalletSDK2.getCoinbaseWalletLogo('text'); | ||
expect(svgUri).toContain("viewBox='0 0 528.15 53.64'"); | ||
expect(svgUri).toContain('fill:%230052ff'); | ||
|
||
svgUri = coinbaseWalletSDK2.getCoinbaseWalletLogo('textWithLogo'); | ||
expect(svgUri).toContain("viewBox='0 0 308.44 77.61'"); | ||
expect(svgUri).toContain('fill:%230052ff'); | ||
|
||
svgUri = coinbaseWalletSDK2.getCoinbaseWalletLogo('textLight'); | ||
expect(svgUri).toContain("viewBox='0 0 528.15 53.64'"); | ||
expect(svgUri).toContain('fill:%23fefefe'); | ||
test('@makeWeb3Provider - return Coinbase Injected Provider', () => { | ||
const injectedProvider = {} as unknown as ProviderInterface; | ||
(getCoinbaseInjectedProvider as jest.Mock).mockReturnValue(injectedProvider); | ||
|
||
svgUri = coinbaseWalletSDK2.getCoinbaseWalletLogo('textWithLogoLight'); | ||
expect(svgUri).toContain("viewBox='0 0 308.44 77.61'"); | ||
expect(svgUri).toContain('fill:%23fefefe'); | ||
}); | ||
const SDK = new CoinbaseWalletSDK({ | ||
appName: 'Test', | ||
appLogoUrl: 'http://coinbase.com/wallet-logo.png', | ||
}); | ||
|
||
describe('extension', () => { | ||
const mockProvider = { close: jest.fn() } as unknown as ProviderInterface; | ||
|
||
beforeAll(() => { | ||
window.coinbaseWalletExtension = mockProvider; | ||
}); | ||
|
||
afterAll(() => { | ||
window.coinbaseWalletExtension = undefined; | ||
}); | ||
|
||
test('@makeWeb3Provider - only walletExtension injected', () => { | ||
// Returns extension provider | ||
expect(coinbaseWalletSDK2.makeWeb3Provider()).toEqual(mockProvider); | ||
}); | ||
|
||
test('@makeWeb3Provider - walletExtension.shouldUseSigner is true', () => { | ||
// Returns extension provider | ||
const mockProvider2 = { | ||
close: jest.fn(), | ||
shouldUseSigner: true, | ||
} as unknown as ProviderInterface; | ||
window.coinbaseWalletExtension = mockProvider2; | ||
expect(SDK.makeWeb3Provider()).toBe(injectedProvider); | ||
}); | ||
|
||
const provider = coinbaseWalletSDK2.makeWeb3Provider(); | ||
expect(provider).not.toEqual(mockProvider2); | ||
}); | ||
test('@makeWeb3Provider - return new CoinbaseWalletProvider', () => { | ||
(getCoinbaseInjectedProvider as jest.Mock).mockReturnValue(undefined); | ||
|
||
test('@makeWeb3Provider, but with smartWalletOnly as true', () => { | ||
const sdk = new CoinbaseWalletSDK({ | ||
appName: 'Test', | ||
appLogoUrl: 'http://coinbase.com/wallet-logo.png', | ||
}); | ||
// Returns extension provider | ||
const provider = sdk.makeWeb3Provider({ | ||
options: 'smartWalletOnly', | ||
}); | ||
expect(provider).toBeTruthy(); | ||
expect(provider).not.toEqual(mockProvider); | ||
}); | ||
const SDK = new CoinbaseWalletSDK({ | ||
appName: 'Test', | ||
appLogoUrl: 'http://coinbase.com/wallet-logo.png', | ||
}); | ||
|
||
describe('cipher provider', () => { | ||
class MockCipherProviderClass { | ||
public isCoinbaseBrowser = true; | ||
} | ||
SDK.makeWeb3Provider(); | ||
|
||
const mockCipherProvider = new MockCipherProviderClass() as unknown as ProviderInterface; | ||
beforeAll(() => { | ||
window.ethereum = mockCipherProvider; | ||
}); | ||
expect(CoinbaseWalletProvider).toHaveBeenCalledWith({ | ||
metadata: { | ||
appName: 'Test', | ||
appLogoUrl: 'http://coinbase.com/wallet-logo.png', | ||
appChainIds: [], | ||
}, | ||
preference: { | ||
options: 'all', | ||
}, | ||
}); | ||
}); | ||
|
||
afterAll(() => { | ||
window.ethereum = undefined; | ||
}); | ||
test('@makeWeb3Provider - default values for metadata', () => { | ||
(getFavicon as jest.Mock).mockReturnValue('https://dapp.xyz/pic.png'); | ||
(getCoinbaseInjectedProvider as jest.Mock).mockReturnValue(undefined); | ||
|
||
test('@makeWeb3Provider', () => { | ||
expect(coinbaseWalletSDK2.makeWeb3Provider()).toEqual(mockCipherProvider); | ||
}); | ||
const SDK = new CoinbaseWalletSDK({ | ||
appName: '', | ||
appLogoUrl: '', | ||
}); | ||
|
||
test('@makeWeb3Provider, it should ignore smartWalletOnly true', () => { | ||
const sdk = new CoinbaseWalletSDK({ | ||
appName: 'Test', | ||
appLogoUrl: 'http://coinbase.com/wallet-logo.png', | ||
}); | ||
expect( | ||
sdk.makeWeb3Provider({ | ||
options: 'smartWalletOnly', | ||
}) | ||
).toEqual(mockCipherProvider); | ||
}); | ||
SDK.makeWeb3Provider(); | ||
|
||
expect(CoinbaseWalletProvider).toHaveBeenCalledWith({ | ||
metadata: { | ||
appName: 'Dapp', | ||
appLogoUrl: 'https://dapp.xyz/pic.png', | ||
appChainIds: [], | ||
}, | ||
preference: { | ||
options: 'all', | ||
}, | ||
}); | ||
}); | ||
}); |
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