Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lykhoyda committed Apr 18, 2024
1 parent ba39634 commit 2b2a187
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ export class FungibleTokenTransfer extends BaseComponent {

connectedCallback(): void {
super.connectedCallback();
void this.transferController.init(
this.environment!,
this.whitelistedSourceNetworks,
this.whitelistedDestinationNetworks,
this.whitelistedSourceResources
);
void this.transferController.init(this.environment!, {
whitelistedSourceNetworks: this.whitelistedSourceNetworks,
whitelistedDestinationNetworks: this.whitelistedDestinationNetworks,
whitelistedSourceResources: this.whitelistedSourceResources
});
}

private onClick = (): void => {
Expand Down
3 changes: 0 additions & 3 deletions packages/widget/src/context/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ export interface ConfigContext {
walletConnectOptions?: WalletConnectOptions;
appMetaData?: AppMetadata;
walletModules?: WalletInit[];
whitelistedSourceNetworks?: string[];
whitelistedDestinationNetworks?: string[];
whitelistedSourceResources?: string[];
}

export const configContext = createContext<ConfigContext>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ export class FungibleTokenTransferController implements ReactiveController {
* {@link Config} from `@buildwithsygma/sygma-sdk-core`
* and emits a {@link SdkInitializedEvent}
* @returns {void}
* @param retryMs
*/
async retryInitSdk(retryMs = 100): Promise<void> {
try {
Expand Down Expand Up @@ -207,26 +206,36 @@ export class FungibleTokenTransferController implements ReactiveController {

async init(
env: Environment,
whitelistedSourceNetworks?: string[],
whitelistedDestinationNetworks?: string[],
whitelistedSourceResources?: string[]
options?: {
whitelistedSourceNetworks?: string[];
whitelistedDestinationNetworks?: string[];
whitelistedSourceResources?: string[];
}
): Promise<void> {
this.host.requestUpdate();
this.env = env;
this.whitelistedSourceNetworks = whitelistedSourceNetworks;
this.whitelistedDestinationNetworks = whitelistedDestinationNetworks;
this.whitelistedSourceResources = whitelistedSourceResources;

this.whitelistedSourceNetworks = options?.whitelistedSourceNetworks;
this.whitelistedDestinationNetworks =
options?.whitelistedDestinationNetworks;
this.whitelistedSourceResources = options?.whitelistedSourceResources;

await this.retryInitSdk();
this.supportedSourceNetworks = this.config
.getDomains()
.filter((network) =>
this.filterWhitelistedNetworks(whitelistedSourceNetworks, network)
this.filterWhitelistedNetworks(
options?.whitelistedSourceNetworks,
network
)
);
this.supportedDestinationNetworks = this.config
.getDomains()
.filter((network) =>
this.filterWhitelistedNetworks(whitelistedDestinationNetworks, network)
this.filterWhitelistedNetworks(
options?.whitelistedDestinationNetworks,
network
)
);
this.host.requestUpdate();
}
Expand Down Expand Up @@ -460,7 +469,7 @@ export class FungibleTokenTransferController implements ReactiveController {
return this.whitelistedSourceResources.includes(route.resource.symbol!);
})
.map((route) => route.resource);

console.log('this.supportedResources', this.supportedResources);
void this.buildTransactions();
this.host.requestUpdate();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ describe('Fungible token Transfer', function () {
});

it('should filter whitelisted networks and resources', async () => {
function containsWhitelistedData<T>(
data: T[],
whitelist: string[],
dataExtractor: (item: T) => string,
errorMessageContext: string
): void {
assert.isNotEmpty(data, 'Data must not be empty.');
data.forEach((item) => {
const key = dataExtractor(item);
assert.isTrue(
whitelist.includes(key),
`${key} expected to be whitelisted in ${errorMessageContext}`
);
});
}

const whitelistedSourceNetworks = ['cronos'];
const whitelistedDestinationNetworks = ['sepolia'];
const whitelistedResources = ['ERC20LRTest'];
Expand Down Expand Up @@ -142,6 +158,23 @@ describe('Fungible token Transfer', function () {
})
);

await fungibleTransfer.updateComplete;
await aTimeout(1000);

containsWhitelistedData(
fungibleTransfer.transferController.supportedSourceNetworks,
whitelistedSourceNetworks,
(network) => network.name,
'transfer controller for source networks'
);

containsWhitelistedData(
fungibleTransfer.transferController.supportedDestinationNetworks,
whitelistedDestinationNetworks,
(network) => network.name,
'transfer controller for destination networks'
);

// Set Source and Destination Networks
fungibleTransfer.transferController.onSourceNetworkSelected(cronosNetwork);
fungibleTransfer.transferController.onDestinationNetworkSelected(
Expand All @@ -160,6 +193,13 @@ describe('Fungible token Transfer', function () {
// Wait for sdk init
await aTimeout(1000);

containsWhitelistedData(
fungibleTransfer.transferController.supportedResources,
whitelistedResources,
(resource) => resource.symbol!,
'transfer controller for resources'
);

assert.isTrue(
whitelistedSourceNetworks.includes(
sygmaSourceNetwork.networks?.[0]?.name
Expand Down

0 comments on commit 2b2a187

Please sign in to comment.