Skip to content

Commit

Permalink
fixes test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
yathishram committed Apr 15, 2022
1 parent b00a3b3 commit beb7fd6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
7 changes: 7 additions & 0 deletions src/contracts/SafientMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ export class SafientMain {
value: string
): Promise<TransactionResponse> => {
try {

if(claimType === ClaimType.DDayBased){
const latestBlockNumber = await this.provider.getBlockNumber();
const latestBlock = await this.provider.getBlock(latestBlockNumber);
dDay = latestBlock.timestamp + dDay
}

this.tx = await this.contract.syncSafe(
creatorAddress,
safeId,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"localhost": {
"chainId": 31337,
"addresses": {
"AutoAppealableArbitrator": "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
"SafientMain": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9"
"AutoAppealableArbitrator": "0x5FbDB2315678afecb367f032d93F642f64180aa3",
"SafientMain": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512"
}
},
"mainnet": {
Expand Down
31 changes: 13 additions & 18 deletions test-sdk/claims.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,12 @@ describe('safientMain', async () => {
const safientMain1 = new SafientMain(beneficiarySigner, chainId);

const beforeTotalNumberOfSafes = await safientMain1.getTotalNumberOfSafes();

// SUCCESS : create a safe(for claimType - SignalBased & signal - won't signal)
await safientMain1.syncSafe(
safeCreatorAddress, // 2nd account
safeId[1],
Types.ClaimType.SignalBased,
6, // 6 seconds because opting SignalBased
10, // 6 seconds because opting SignalBased
0,
'', // no metaevidence because SignalBased
'' // no safe maintenence fee because SignalBased
Expand All @@ -140,7 +139,7 @@ describe('safientMain', async () => {
const safe = await safientMain1.getSafeBySafeId(safeId[1]);
expect(safe.createdBy).to.equal(safeCreatorAddress);
expect(safe.beneficiary).to.equal(beneficiaryAddress);
expect(Number(safe.signalingPeriod)).to.equal(6); // 6 seconds
expect(Number(safe.signalingPeriod)).to.equal(10); // 6 seconds
expect(Number(safe.endSignalTime)).to.equal(0);
expect(Number(safe.latestSignalTime)).to.equal(0);
expect(Number(safe.claimType)).to.equal(0); // SignalBased
Expand All @@ -151,7 +150,7 @@ describe('safientMain', async () => {
beneficiaryAddress, // 2nd account
safeId[2],
Types.ClaimType.SignalBased,
6,
10,
0,
'',
''
Expand All @@ -175,7 +174,7 @@ describe('safientMain', async () => {
// SUCCESS : create a claim (ArbitrationBased) on safeId1
const tx = await safientMain.createClaim(safeId[0], metaevidenceOrEvidenceURI);
const txReceipt = await tx.wait();
claimIdOfSafeId0 = txReceipt.events[2].args[2];
claimIdOfSafeId0 = txReceipt.events[2].args[1];

expect(await safientMain.getTotalNumberOfClaims()).to.equal(beforeTotalNumberOfClaims + 1);

Expand All @@ -192,7 +191,7 @@ describe('safientMain', async () => {
// SUCCESS : create claim on safeId2
tx = await safientMain.createClaim(safeId[1], '');
txReceipt = await tx.wait();
claimIdOfSafeId1 = txReceipt.events[0].args[2];
claimIdOfSafeId1 = parseInt(txReceipt.events[0].args[1]._hex)

const safeWithSafeId1 = await safientMain.getSafeBySafeId(safeId[1]);
expect(safeWithSafeId1.claimsCount).to.equal(1);
Expand All @@ -204,8 +203,7 @@ describe('safientMain', async () => {
// SUCCESS : create claim on safeId3
tx = await safientMain.createClaim(safeId[2], '');
txReceipt = await tx.wait();
claimIdOfSafeId2 = txReceipt.events[0].args[2];

claimIdOfSafeId2 = parseInt(txReceipt.events[0].args[1]._hex)
const safeWithSafeId2 = await safientMain.getSafeBySafeId(safeId[2]);
expect(safeWithSafeId2.claimsCount).to.equal(1);

Expand All @@ -227,7 +225,7 @@ describe('safientMain', async () => {
const mineNewBlock = new Promise((resolve, reject) => {
setTimeout(() => {
resolve(provider.send('evm_mine'));
}, 7000);
}, 11000);
});
const result = await mineNewBlock;

Expand Down Expand Up @@ -328,17 +326,14 @@ describe('safientMain', async () => {
const safientMainBeneficiary = new SafientMain(beneficiarySigner, chainId);
const safientMainAccountX = new SafientMain(accountXSigner, chainId);

const latestBlockNumber = await provider.getBlockNumber();
const latestBlock = await provider.getBlock(latestBlockNumber);
const now = latestBlock.timestamp;

// SUCCESS : create another safe with safeId4 (for claimType - DDayBased) with DDay set to 6 seconds
await safientMainCreator.createSafe(beneficiaryAddress, safeId[3], Types.ClaimType.DDayBased, 0, now + 6, '', '');
await safientMainCreator.createSafe(beneficiaryAddress, safeId[3], Types.ClaimType.DDayBased, 0, 6, '', '');

// create a claim - before D-Day (claim should fail)
const tx1 = await safientMainBeneficiary.createClaim(safeId[3], '');
const txReceipt1 = await tx1.wait();
const claimId1 = txReceipt1.events[0].args[2];
const claimId1 = txReceipt1.events[0].args[1];
const claimID1 = parseInt(claimId1._hex);

// check claim status (DDayBased)
Expand All @@ -356,7 +351,7 @@ describe('safientMain', async () => {
// create a claim - before D-Day (claim should pass)
const tx2 = await safientMainBeneficiary.createClaim(safeId[3], '');
const txReceipt2 = await tx2.wait();
const claimId2 = txReceipt2.events[0].args[2];
const claimId2 = txReceipt2.events[0].args[1];
const claimID2 = parseInt(claimId2._hex);

// check claim status (DDayBased)
Expand All @@ -381,7 +376,7 @@ describe('safientMain', async () => {
// create a claim - before D-Day (6 seconds) (claim should fail)
const tx1 = await safientMainBeneficiary.createClaim(safeId[4], '');
const txReceipt1 = await tx1.wait();
const claimId1 = txReceipt1.events[0].args[2];
const claimId1 = txReceipt1.events[0].args[1];
const claimID1 = parseInt(claimId1._hex);

// check claim status (DDayBased)
Expand All @@ -406,7 +401,7 @@ describe('safientMain', async () => {
// create a claim - before D-Day (12 seconds) (claim should fail)
const tx2 = await safientMainBeneficiary.createClaim(safeId[4], '');
const txReceipt2 = await tx2.wait();
const claimId2 = txReceipt2.events[0].args[2];
const claimId2 = txReceipt2.events[0].args[1];
const claimID2 = parseInt(claimId2._hex);

// check claim status (DDayBased)
Expand All @@ -424,7 +419,7 @@ describe('safientMain', async () => {
// create a claim - after D-Day (10 + 2 = 12 seconds) (claim should pass)
const tx3 = await safientMainBeneficiary.createClaim(safeId[4], '');
const txReceipt3 = await tx3.wait();
const claimId3 = txReceipt3.events[0].args[2];
const claimId3 = txReceipt3.events[0].args[1];
const claimID3 = parseInt(claimId3._hex);

// check claim status (DDayBased)
Expand Down

0 comments on commit beb7fd6

Please sign in to comment.