Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/stellar-wallet-snap/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Client request handler `confirmSend` now throws when signing, or submission fails after the user confirms, instead of returning a JSON error response such as `{ valid: false, errors }` ([#550](https://github.com/MetaMask/internal-snaps/pull/550))
- Bump `@stellar/stellar-sdk` from `^17.2.1` to `^17.4.0` ([#545](https://github.com/MetaMask/internal-snaps/pull/545))
- Retry transient Token API, Price API, and Security Alerts API failures with bounded timeouts and circuit breaking ([#534](https://github.com/MetaMask/internal-snaps/pull/534))
- Retry transient RPC and Horizon failures with bounded timeouts and circuit breaking ([#551](https://github.com/MetaMask/internal-snaps/pull/551))
- Transaction submission still uses the raw RPC client and does not apply the fetch policy.

## [2.0.0]

Expand Down
34 changes: 34 additions & 0 deletions packages/stellar-wallet-snap/src/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ const FULL_ENVIRONMENT = {
rpcUrl: 'https://rpc.mainnet.example.com',
horizonUrl: 'https://horizon.mainnet.example.com',
explorerBaseUrl: 'https://explorer.mainnet.example.com',
timeout: '5000',
},
[KnownCaip2ChainId.Testnet]: {
rpcUrl: 'https://rpc.testnet.example.com',
horizonUrl: 'https://horizon.testnet.example.com',
explorerBaseUrl: 'https://explorer.testnet.example.com',
timeout: '8000',
},
},
selectedNetwork: KnownCaip2ChainId.Mainnet,
Expand Down Expand Up @@ -118,16 +120,36 @@ describe('ConfigProvider', () => {
rpcUrl: 'https://rpc.mainnet.example.com',
horizonUrl: 'https://horizon.mainnet.example.com',
explorerBaseUrl: 'https://explorer.mainnet.example.com',
timeout: 5000,
},
[KnownCaip2ChainId.Testnet]: {
rpcUrl: 'https://rpc.testnet.example.com',
horizonUrl: 'https://horizon.testnet.example.com',
explorerBaseUrl: 'https://explorer.testnet.example.com',
timeout: 8000,
},
});
expect(config.selectedNetwork).toBe(KnownCaip2ChainId.Mainnet);
});

it('defaults an empty network timeout', () => {
const { config } = new BaseConfigProvider(
{
...FULL_ENVIRONMENT,
networks: {
...FULL_ENVIRONMENT.networks,
[KnownCaip2ChainId.Mainnet]: {
...FULL_ENVIRONMENT.networks[KnownCaip2ChainId.Mainnet],
timeout: '',
},
},
},
ConfigStruct,
);

expect(config.networks[KnownCaip2ChainId.Mainnet].timeout).toBe(10_000);
});

it.each([
['a malformed RPC URL', { STELLAR_RPC_URL_MAINNET: 'not-a-url' }],
['a malformed Horizon URL', { STELLAR_HORIZON_URL_MAINNET: 'not-a-url' }],
Expand All @@ -143,6 +165,18 @@ describe('ConfigProvider', () => {
},
},
],
[
'a network timeout below the minimum',
{
networks: {
...FULL_ENVIRONMENT.networks,
[KnownCaip2ChainId.Mainnet]: {
...FULL_ENVIRONMENT.networks[KnownCaip2ChainId.Mainnet],
timeout: '50',
},
},
},
],
])('fails fast for %s', (_label, overrides) => {
expect(
() =>
Expand Down
1 change: 1 addition & 0 deletions packages/stellar-wallet-snap/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const networkConfigStruct = object({
rpcUrl: UrlStruct,
horizonUrl: UrlStruct,
explorerBaseUrl: UrlStruct,
timeout: parseIntegerStruct(100, 10_000),
});

/**
Expand Down
14 changes: 9 additions & 5 deletions packages/stellar-wallet-snap/src/services/network/MultiCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export type StellarRouterParams = {
simulationAccount: string;
};

export type SimulateTransaction = (
transaction: Transaction,
) => ReturnType<rpc.Server['simulateTransaction']>;

export class InvocationV0 {
contract: Address | string;

Expand Down Expand Up @@ -78,22 +82,22 @@ export class InvocationV1 {
}

export class MultiCall {
readonly #rpcClient: rpc.Server;
readonly #simulateTransaction: SimulateTransaction;

readonly #simulationAccount: string;

readonly #routerContract: StellarRouterContract;

constructor({
rpcClient,
simulateTransaction,
simulationAccount = SIMULATION_ACCOUNT,
routerContract = StellarRouterContract.V0,
}: {
rpcClient: rpc.Server;
simulateTransaction: SimulateTransaction;
simulationAccount?: string;
routerContract?: StellarRouterContract;
}) {
this.#rpcClient = rpcClient;
this.#simulateTransaction = simulateTransaction;
this.#simulationAccount = simulationAccount;
this.#routerContract = routerContract;
}
Expand Down Expand Up @@ -169,7 +173,7 @@ export class MultiCall {
.addOperation(this.exec(callerAccount, invocations))
.build();

const sim = await this.#rpcClient.simulateTransaction(tx);
const sim = await this.#simulateTransaction(tx);

if (rpc.Api.isSimulationError(sim)) {
throw new Error(String(sim.error));
Expand Down
Loading
Loading