Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
louilinn committed Sep 5, 2023
1 parent 33bd9af commit 3f8d151
Showing 1 changed file with 37 additions and 24 deletions.
61 changes: 37 additions & 24 deletions test/trust.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ describe('Trust', () => {
expect(connection.safeAddress).toBe(safeAddressB);
expect(connection.isIncoming).toBe(true);
expect(connection.isOutgoing).toBe(false);
expect(connection.limitPercentageIn).toBe(44);
expect(connection.limitPercentageOut).toBe(0);

let otherConnection = await core.utils.loop(
() => {
Expand All @@ -67,8 +65,6 @@ describe('Trust', () => {
expect(otherConnection.safeAddress).toBe(safeAddressA);
expect(otherConnection.isIncoming).toBe(false);
expect(otherConnection.isOutgoing).toBe(true);
expect(otherConnection.limitPercentageIn).toBe(0);
expect(otherConnection.limitPercentageOut).toBe(44);

// Test bidirectional trust connections
// B trusts A
Expand All @@ -91,8 +87,6 @@ describe('Trust', () => {
expect(otherConnection.safeAddress).toBe(safeAddressA);
expect(otherConnection.isIncoming).toBe(true);
expect(otherConnection.isOutgoing).toBe(true);
expect(otherConnection.limitPercentageIn).toBe(72);
expect(otherConnection.limitPercentageOut).toBe(44);

// This should not be true as we don't have enough
// trust connections yet
Expand Down Expand Up @@ -141,38 +135,57 @@ describe('Trust', () => {
});

it('network should give no mutually trusted connections', async () => {
const network = await core.utils.loop(async () => {
return await core.trust.getNetwork(accountA, {
safeAddress: safeAddressA,
});
});

const mutualConnectionsAC = network.find(
(element) => element.safeAddress === safeAddressC,
).mutualConnections;
expect(mutualConnectionsAC.length).toBe(0);
});

it('network should give correct mutually trusted connections', async () => {
// A trusts B
await core.trust.addConnection(accountA, {
user: safeAddressB,
canSendTo: safeAddressA,
limitPercentage: 100,
});
// A trusts C
await core.trust.addConnection(accountA, {
user: safeAddressB,
canSendTo: safeAddressA,
limitPercentage: 100,
});

const network = await core.utils.loop(
async () => {
return await core.trust.getNetwork(accountA, {
safeAddress: safeAddressA,
});
},
(network) => {
// console.log(network);
return network.length === 1;
},
{ label: 'Wait for trust network to be updated' },
);

const networkAC = network.find(
(element) => element.safeAddress === safeAddressC,
);
expect(networkAC).toBe(undefined);
});

it('network should give correct mutually trusted connections', async () => {
// C trust B
await core.trust.addConnection(accountA, {
user: safeAddressB,
canSendTo: safeAddressC,
limitPercentage: 50,
});

const network = await core.utils.loop(async () => {
return await core.trust.getNetwork(accountA, {
safeAddress: safeAddressA,
});
});
const network = await core.utils.loop(
async () => {
return await core.trust.getNetwork(accountA, {
safeAddress: safeAddressA,
});
},
(network) =>
network.find((element) => element.safeAddress === safeAddressC)
.mutualConnections.length === 1,
{ label: 'Wait for trust network to be updated' },
);

const mutualConnectionsAC = network.find(
(element) => element.safeAddress === safeAddressC,
Expand Down

0 comments on commit 3f8d151

Please sign in to comment.