@cardano-sdk/e2e 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ import { Cardano } from '@cardano-sdk/core';
1
2
  import { Observable } from 'rxjs';
2
3
  import { Origin } from '@cardano-sdk/dapp-connector';
3
4
  import { RemoteApiProperties, RemoteApiPropertyType } from '@cardano-sdk/web-extension';
@@ -11,11 +12,13 @@ export interface UserPromptService {
11
12
  export interface BackgroundServices {
12
13
  adaUsd$: Observable<number>;
13
14
  clearAllowList(): Promise<void>;
15
+ getPoolIds(count: number): Promise<Cardano.StakePool[]>;
14
16
  }
15
17
 
16
18
  export const adaPriceProperties: RemoteApiProperties<BackgroundServices> = {
17
19
  adaUsd$: RemoteApiPropertyType.HotObservable,
18
- clearAllowList: RemoteApiPropertyType.MethodReturningPromise
20
+ clearAllowList: RemoteApiPropertyType.MethodReturningPromise,
21
+ getPoolIds: RemoteApiPropertyType.MethodReturningPromise
19
22
  };
20
23
 
21
24
  export const logger = console;
@@ -1,3 +1,4 @@
1
+ /* eslint-disable max-statements */
1
2
  import { getObservableWalletName } from '../extension/const';
2
3
 
3
4
  const switchToWalletUi = async () => {
@@ -11,6 +12,8 @@ const switchToWalletUi = async () => {
11
12
  });
12
13
  };
13
14
 
15
+ const NUM_POOLS = 3;
16
+
14
17
  describe('wallet', () => {
15
18
  const pWalletFound = '#root > div > p:nth-child(4)';
16
19
  const btnRefresh = '#root > div > button';
@@ -37,6 +40,11 @@ describe('wallet', () => {
37
40
  const dappStakingAddress = '#root > div > p:nth-child(12)';
38
41
  const dappUsedAddress = '#root > div > p:nth-child(13)';
39
42
 
43
+ const btnDelegate = '#multiDelegation .delegate button';
44
+ const spanPoolIds = '#multiDelegation .delegate .pools';
45
+ const liPools = '#multiDelegation .distribution li';
46
+ const liPercents = '#multiDelegation .distribution li .percent';
47
+
40
48
  // The address is filled in by the tests, which are order dependent
41
49
  let walletAddr1 = '';
42
50
  let walletStakeAddr1 = '';
@@ -67,12 +75,12 @@ describe('wallet', () => {
67
75
  await expect($(divAdaPrice)).toHaveText('2.99');
68
76
  });
69
77
 
70
- describe('ui grants access and creates key agent', () => {
78
+ describe('web-extension grants access and creates key agent', () => {
71
79
  before(async () => {
72
80
  await $(btnGrantAccess).click();
73
81
  await $(btnActivateWallet1).click();
74
82
  });
75
- it('ui has access to remote ObservableWallet and SupplyDistribution', async () => {
83
+ it('web-extension has access to remote ObservableWallet and SupplyDistribution', async () => {
76
84
  await browser.waitUntil(async () => {
77
85
  try {
78
86
  BigInt(await $(spanBalance).getText());
@@ -88,6 +96,9 @@ describe('wallet', () => {
88
96
  expect(walletStakeAddr1).toHaveTextContaining('stake');
89
97
  await expect($(activeWalletName)).toHaveText(getObservableWalletName(0));
90
98
  });
99
+ });
100
+
101
+ describe('dapp can use cip30 wallet api', () => {
91
102
  it('dapp has access to cip30 WalletApi', async () => {
92
103
  await browser.switchWindow('React App');
93
104
  await expect($(pNetworkId)).toHaveText('Network Id (0 = testnet; 1 = mainnet): 0');
@@ -105,11 +116,49 @@ describe('wallet', () => {
105
116
  await expect($(dappStakingAddress)).toHaveTextContaining(walletStakeAddr1);
106
117
  await expect($(dappUsedAddress)).toHaveTextContaining(walletAddr1);
107
118
  });
119
+ });
108
120
 
121
+ describe('web-extension can build transactions and use wallet manager', () => {
109
122
  it('can build and sign a transaction', async () => {
110
123
  await switchToWalletUi();
111
124
  await buildAndSign();
112
125
  });
126
+
127
+ it('can delegate to multiple pools', async () => {
128
+ (await $(btnDelegate)).click();
129
+
130
+ // There should be 3 pools available
131
+ await browser.waitUntil(async () => {
132
+ try {
133
+ const poolIds = await $(spanPoolIds).getText();
134
+ return poolIds.split(' ').length === NUM_POOLS;
135
+ } catch {
136
+ return false;
137
+ }
138
+ });
139
+
140
+ // Delegation transaction was submitted successfully
141
+ const txId = await $('#multiDelegation .delegateTxId').getText();
142
+ expect(txId).toHaveTextContaining('TxId');
143
+
144
+ // Wallet reports delegating to 3 pools
145
+ await browser.waitUntil(
146
+ async () => {
147
+ try {
148
+ const delegatedPools = await $$(liPools);
149
+ return delegatedPools.length === NUM_POOLS;
150
+ } catch {
151
+ return false;
152
+ }
153
+ },
154
+ { timeout: 30_000, timeoutMsg: 'Expected wallet.delegation.distribution to report 3 delegations' }
155
+ );
156
+
157
+ // Check wallet delegation distribution is applied and displayed correctly
158
+ const delegationPercents = await $$(liPercents).map((el) => el.getText());
159
+ expect(delegationPercents.map((percent) => Math.round(Number.parseFloat(percent)))).toEqual([10, 30, 60]);
160
+ });
161
+
113
162
  it('can switch to another wallet', async () => {
114
163
  // Automatically deactivates first wallet, but keeps the store available for future activation
115
164
  await $(btnActivateWallet2).click();