Skip to content

Commit

Permalink
Fix trust limits as an organization
Browse files Browse the repository at this point in the history
  • Loading branch information
llunaCreixent committed Jun 2, 2021
1 parent 04e45b6 commit 821233f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/trust.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import checkAccount from '~/common/checkAccount';
import checkOptions from '~/common/checkOptions';

const DEFAULT_LIMIT_PERCENTAGE = 50;
const DEFAULT_USER_LIMIT_PERCENTAGE = 50;
const DEFAULT_ORG_LIMIT_PERCENTAGE = 100;

const DEFAULT_TRUST_LIMIT = 3;
const NO_LIMIT_PERCENTAGE = 0;

Expand Down Expand Up @@ -275,10 +277,18 @@ export default function createTrustModule(web3, contracts, utils) {
},
limitPercentage: {
type: 'number',
default: DEFAULT_LIMIT_PERCENTAGE,
default: DEFAULT_USER_LIMIT_PERCENTAGE,
},
});

const isOrgSignedup = await hub.methods
.organizations(options.canSendTo)
.call();

if (isOrgSignedup) {
options.limitPercentage = DEFAULT_ORG_LIMIT_PERCENTAGE;
}

const txData = await hub.methods
.trust(options.user, options.limitPercentage)
.encodeABI();
Expand Down
17 changes: 17 additions & 0 deletions test/organization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import { deploySafeAndToken } from './helpers/transactions';

describe('Organization', () => {
let account;
let otherAccount;
let core;
let safeAddress;
let userSafeAddress;
let otherUserSafeAddress;

beforeAll(async () => {
account = getAccount(0);
otherAccount = getAccount(1);
core = createCore();

// First deploy users Safe ..
Expand All @@ -30,6 +33,10 @@ describe('Organization', () => {
await loop('Wait until Safe for organization got deployed', () =>
web3.eth.getCode(safeAddress),
);

// Then deploy other users Safe .. to test trust connections
const otherUser = await deploySafeAndToken(core, otherAccount);
otherUserSafeAddress = otherUser.safeAddress;
});

it('should check if safe has enough funds for organization to be created', async () => {
Expand Down Expand Up @@ -104,4 +111,14 @@ describe('Organization', () => {

expect(web3.utils.isHexStrict(txHash)).toBe(true);
});

it('should be able to trust a user as an organization', async () => {
const txHash = await core.trust.addConnection(account, {
user: otherUserSafeAddress,
canSendTo: safeAddress,
limitPercentage: 44,
});

expect(web3.utils.isHexStrict(txHash)).toBe(true);
});
});

0 comments on commit 821233f

Please sign in to comment.