Skip to content

Commit

Permalink
change tip types format
Browse files Browse the repository at this point in the history
  • Loading branch information
thepiwo committed Feb 19, 2021
1 parent af91cf9 commit e86da61
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion test/aex9TippingTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe('AEX9 Tipping Contract', () => {
assert.deepEqual(state.urls.find(u => u.url === 'other.test').token_unclaimed_amount, []);

assert.equal(state.tips.find(u => u.title === 'Hello World 3').amount, 0);
assert.equal(state.tips.find(u => u.title === 'Hello World 3').type, "TokenTip");
assert.equal(state.tips.find(u => u.title === 'Hello World 3').type, "TOKEN_TIP");
assert.equal(state.tips.find(u => u.title === 'Hello World 3').token_amount, 123);
assert.equal(state.tips.find(u => u.title === 'Hello World 3').token, tokenContract1.deployInfo.address);
});
Expand Down
4 changes: 2 additions & 2 deletions test/directTippingTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('Direct Tipping Contract', () => {

const state = TippingContractUtil.getTipsRetips(await contract.methods.get_state());
assert.equal(state.tips.find(t => t.id === "0_v2").amount, "10000");
assert.equal(state.tips.find(t => t.id === "0_v2").type, "DirectAeTip");
assert.equal(state.tips.find(t => t.id === "0_v2").type, "DIRECT_AE_TIP");
assert.lengthOf(state.tips, 1);

const balanceAfter = await client.getBalance(wallets[3].publicKey);
Expand All @@ -96,7 +96,7 @@ describe('Direct Tipping Contract', () => {

const state = TippingContractUtil.getTipsRetips(await contract.methods.get_state());
assert.equal(state.tips.find(t => t.id === "1_v2").token_amount, "333");
assert.equal(state.tips.find(t => t.id === "1_v2").type, "DirectTokenTip");
assert.equal(state.tips.find(t => t.id === "1_v2").type, "DIRECT_TOKEN_TIP");
assert.lengthOf(state.tips, 2);
});
});
2 changes: 1 addition & 1 deletion test/tippingV1Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('Tipping V1 Contract', () => {
assert.lengthOf(state.tips, 3);
assert.lengthOf(state.urls, 2);
assert.equal(state.tips.find(t => t.id === "0_v1").total_unclaimed_amount, "100");
assert.equal(state.tips.find(t => t.id === "0_v1").type, "AeTip");
assert.equal(state.tips.find(t => t.id === "0_v1").type, "AE_TIP");
assert.equal(state.tips.find(t => t.id === "1_v1").total_unclaimed_amount, "100");
assert.equal(state.tips.find(t => t.id === "2_v1").total_unclaimed_amount, "100");
assert.equal((await contract.methods.unclaimed_for_url('domain.test')).decodedResult, 100 + 100);
Expand Down
2 changes: 1 addition & 1 deletion test/tippingV2Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('Tipping V2 Contract', () => {
assert.lengthOf(state.tips, 3);
assert.lengthOf(state.urls, 2);
assert.equal(state.tips.find(t => t.id === "0_v2").total_unclaimed_amount, "100");
assert.equal(state.tips.find(t => t.id === "0_v2").type, "AeTip");
assert.equal(state.tips.find(t => t.id === "0_v2").type, "AE_TIP");
assert.equal(state.tips.find(t => t.id === "1_v2").total_unclaimed_amount, "100");
assert.equal(state.tips.find(t => t.id === "2_v2").total_unclaimed_amount, "100");
assert.equal((await contract.methods.unclaimed_for_url('domain.test')).decodedResult[0], 100 + 100);
Expand Down
2 changes: 1 addition & 1 deletion test/tippingV3Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('Tipping V3 Contract', () => {
const state = TippingContractUtil.getTipsRetips(await contract.methods.get_state());
assert.lengthOf(state.tips, 2);
assert.equal(state.tips.find(t => t.id === "1_v3").title, 'a');
assert.equal(state.tips.find(t => t.id === "1_v3").type, 'PostWithoutTip');
assert.equal(state.tips.find(t => t.id === "1_v3").type, 'POST_WITHOUT_TIP');
assert.deepEqual(state.tips.find(t => t.id === "1_v3").media, ['b', 'c']);
});

Expand Down
12 changes: 6 additions & 6 deletions util/tippingContractUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ const aggregateState = (returnState) => {
switch (tipType) {
case 'AeTip':
data = tipData[0];
data.type = tipType;
data.type = 'AE_TIP';
data.url_id = tipData[1];
data.amount = tipData[2];
data.claim_gen = tipData[3];
break;
case 'TokenTip':
data = tipData[0];
data.type = tipType;
data.type = 'TOKEN_TIP';
data.url_id = tipData[1];
data.token = tipData[2].token;
data.token_amount = tipData[2].amount;
Expand All @@ -96,27 +96,27 @@ const aggregateState = (returnState) => {
break;
case 'DirectAeTip':
data = tipData[0];
data.type = tipType;
data.type = 'DIRECT_AE_TIP';
data.receiver = tipData[1];
data.amount = tipData[2];
break;
case 'DirectTokenTip':
data = tipData[0];
data.type = tipType;
data.type = 'DIRECT_TOKEN_TIP';
data.receiver = tipData[1];
data.token = tipData[2].token;
data.token_amount = tipData[2].amount;
data.amount = 0;
break;
case 'PostWithoutTip':
data = tipData[0];
data.type = tipType;
data.type = 'POST_WITHOUT_TIP';
data.media = tipData[1];
data.amount = 0;
break;
default:
data = tipTypeData; // Fallback for old contract state format
data.type = 'AeTip';
data.type = 'AE_TIP';
break;
}

Expand Down

0 comments on commit e86da61

Please sign in to comment.