Skip to content

Change the stakeholders in solo e2e tests scheme #1554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2019
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
40 changes: 20 additions & 20 deletions test/src/e2e.long/reward2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ describe("reward2", function() {

// nodeA creates 2 blocks
{
await nodeA.pay(aliceAddress, 100); // +100 +50 +10*2/10 for alice in nodeA, +10*1/10 for bob
await nodeA.pay(aliceAddress, 100); // +100 +50 +10*4/10 for alice in nodeA, +10*3/10 for bob
expect(
await nodeA.sdk.rpc.chain.getBalance(aliceAddress)
).to.deep.equal(new U64(50 + 100 + 50 + 2));
).to.deep.equal(new U64(50 + 100 + 50 + 4));
expect(
await nodeA.sdk.rpc.chain.getBalance(bobAddress)
).to.deep.equal(new U64(1));
).to.deep.equal(new U64(3));
await nodeA.sdk.rpc.chain.sendSignedTransaction(
nodeA.sdk.core
.createPayTransaction({
Expand All @@ -115,32 +115,32 @@ describe("reward2", function() {
fee: 10,
seq: 0
})
); // +50 -5 + 10*2/10 -10 for alice, +5 +10*1/10 for bob in nodeA
); // +50 -5 + 10*4/10 -10 for alice, +5 +10*3/10 for bob in nodeA

expect(
await nodeA.sdk.rpc.chain.getBalance(aliceAddress)
).to.deep.equal(new U64(50 + 100 + 50 + 2 + 50 - 5 + 2 - 10));
).to.deep.equal(new U64(50 + 100 + 50 + 4 + 50 - 5 + 4 - 10));
expect(
await nodeA.sdk.rpc.chain.getBalance(bobAddress)
).to.deep.equal(new U64(1 + 5 + 1));
).to.deep.equal(new U64(3 + 5 + 3));
}

// nodeB creates 3 blocks
{
await nodeB.pay(aliceAddress, 200); // +200 +10*2/10 for alice, +50 +10*1/10 for bob in nodeB
await nodeB.pay(aliceAddress, 200); // +200 +10*4/10 for alice, +50 +10*3/10 for bob in nodeB
expect(
await nodeB.sdk.rpc.chain.getBalance(aliceAddress)
).to.deep.equal(new U64(50 + 200 + 2));
).to.deep.equal(new U64(50 + 200 + 4));
expect(
await nodeB.sdk.rpc.chain.getBalance(bobAddress)
).to.deep.equal(new U64(50 + 1));
await nodeB.pay(bobAddress, 300); // 10*2/10 for alice, +300 +50 +10*1/10 for bob in nodeB
).to.deep.equal(new U64(50 + 3));
await nodeB.pay(bobAddress, 300); // 10*4/10 for alice, +300 +50 +10*3/10 for bob in nodeB
expect(
await nodeB.sdk.rpc.chain.getBalance(aliceAddress)
).to.deep.equal(new U64(50 + 200 + 2 + 2));
).to.deep.equal(new U64(50 + 200 + 4 + 4));
expect(
await nodeB.sdk.rpc.chain.getBalance(bobAddress)
).to.deep.equal(new U64(50 + 1 + 300 + 50 + 1));
).to.deep.equal(new U64(50 + 3 + 300 + 50 + 3));
await nodeB.sdk.rpc.chain.sendSignedTransaction(
nodeB.sdk.core
.createPayTransaction({
Expand All @@ -152,13 +152,13 @@ describe("reward2", function() {
fee: 10,
seq: 0
})
); // -15 -10 +10*2/10 for alice. +50 + 15 + 10*1/10 for bob in nodeB
); // -15 -10 +10*4/10 for alice. +50 + 15 + 10*3/10 for bob in nodeB
expect(
await nodeB.sdk.rpc.chain.getBalance(aliceAddress)
).to.deep.equal(new U64(50 + 200 + 2 + 2 - 15 - 10 + 2));
).to.deep.equal(new U64(50 + 200 + 4 + 4 - 15 - 10 + 4));
expect(
await nodeB.sdk.rpc.chain.getBalance(bobAddress)
).to.deep.equal(new U64(50 + 1 + 300 + 50 + 1 + 50 + 15 + 1));
).to.deep.equal(new U64(50 + 3 + 300 + 50 + 3 + 50 + 15 + 3));
}

// sync. nodeA now sees nodeB's state
Expand All @@ -174,23 +174,23 @@ describe("reward2", function() {

expect(
await nodeA.sdk.rpc.chain.getBalance(aliceAddress)
).to.deep.equal(new U64(50 + 200 + 2 + 2 - 15 - 10 + 2));
).to.deep.equal(new U64(50 + 200 + 4 + 4 - 15 - 10 + 4));
expect(
await nodeA.sdk.rpc.chain.getBalance(bobAddress)
).to.deep.equal(new U64(50 + 1 + 300 + 50 + 1 + 50 + 15 + 1));
).to.deep.equal(new U64(50 + 3 + 300 + 50 + 3 + 50 + 15 + 3));
}

// nodeA creates a block
{
await nodeA.pay(aliceAddress, 1000); // +1000 + 50 + 10*2/10 for alice, 10*1/10 for bob
await nodeA.pay(aliceAddress, 1000); // +1000 + 50 + 10*4/10 for alice, 10*3/10 for bob
expect(
await nodeA.sdk.rpc.chain.getBalance(aliceAddress)
).to.deep.equal(
new U64(50 + 200 + 2 + 2 - 15 - 10 + 2 + 1000 + 50 + 2)
new U64(50 + 200 + 4 + 4 - 15 - 10 + 4 + 1000 + 50 + 4)
);
expect(
await nodeA.sdk.rpc.chain.getBalance(bobAddress)
).to.deep.equal(new U64(50 + 1 + 300 + 50 + 1 + 50 + 15 + 1 + 1));
).to.deep.equal(new U64(50 + 3 + 300 + 50 + 3 + 50 + 15 + 3 + 3));
}
}).timeout(120_000);

Expand Down
109 changes: 73 additions & 36 deletions test/src/e2e/reward.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import { expect } from "chai";
import { PlatformAddress, U64 } from "codechain-sdk/lib/core/classes";
import { U64 } from "codechain-sdk/lib/core/classes";
import "mocha";
import {
aliceAddress,
aliceSecret,
bobAddress,
carolAddress,
daveAddress,
faucetAddress
} from "../helper/constants";
import CodeChain from "../helper/spawn";
Expand Down Expand Up @@ -51,20 +53,30 @@ describe("Reward = 50, 1 miner", function() {
expect(await node.sdk.rpc.chain.getBalance(bobAddress)).to.deep.equal(
new U64(0)
);
expect(await node.sdk.rpc.chain.getBalance(carolAddress)).to.deep.equal(
new U64(0)
);
expect(await node.sdk.rpc.chain.getBalance(daveAddress)).to.deep.equal(
new U64(0)
);
});

it("Mining a block with 1 transaction", async function() {
await node.sendPayTx({ fee: 10 });

expect(
await node.sdk.rpc.chain.getBalance(faucetAddress)
).to.deep.equal(
FAUCET_INITIAL_CCS.minus(10 /* fee */).plus(7 /* share */)
);
).to.deep.equal(FAUCET_INITIAL_CCS.minus(10 /* fee */));
expect(await node.sdk.rpc.chain.getBalance(aliceAddress)).to.deep.equal(
new U64(2 /* share */).plus(BLOCK_REWARD)
new U64(4 /* share */).plus(BLOCK_REWARD)
);
expect(await node.sdk.rpc.chain.getBalance(bobAddress)).to.deep.equal(
new U64(3 /* share */)
);
expect(await node.sdk.rpc.chain.getBalance(carolAddress)).to.deep.equal(
new U64(2 /* share */)
);
expect(await node.sdk.rpc.chain.getBalance(daveAddress)).to.deep.equal(
new U64(1 /* share */)
);
});
Expand All @@ -85,20 +97,28 @@ describe("Reward = 50, 1 miner", function() {
});
await node.sdk.rpc.devel.startSealing();

const TOTAL_FEE = 10 + 10 + 15;
const TOTAL_MIN_FEE = MIN_FEE_PAY * 3;
expect(
await node.sdk.rpc.chain.getBalance(faucetAddress)
).to.deep.equal(
FAUCET_INITIAL_CCS.minus(10 + 10 + 15 /* fee */).plus(
21 /* share */
)
);
).to.deep.equal(FAUCET_INITIAL_CCS.minus(TOTAL_FEE));
expect(await node.sdk.rpc.chain.getBalance(aliceAddress)).to.deep.equal(
new U64(6 /* share */)
.plus(10 + 10 + 15 - 3 * MIN_FEE_PAY /* share remaining */)
new U64(Math.floor((TOTAL_MIN_FEE * 4) / 10) /* share */)
.plus(TOTAL_FEE) // block author get the remaining fee
.minus(Math.floor((TOTAL_MIN_FEE * 4) / 10))
.minus(Math.floor((TOTAL_MIN_FEE * 3) / 10))
.minus(Math.floor((TOTAL_MIN_FEE * 2) / 10))
.minus(Math.floor((TOTAL_MIN_FEE * 1) / 10))
.plus(BLOCK_REWARD)
);
expect(await node.sdk.rpc.chain.getBalance(bobAddress)).to.deep.equal(
new U64(3 /* share */)
new U64(Math.floor((TOTAL_MIN_FEE * 3) / 10) /* share */)
);
expect(await node.sdk.rpc.chain.getBalance(carolAddress)).to.deep.equal(
new U64(Math.floor((TOTAL_MIN_FEE * 2) / 10) /* share */)
);
expect(await node.sdk.rpc.chain.getBalance(daveAddress)).to.deep.equal(
new U64(Math.floor((TOTAL_MIN_FEE * 1) / 10) /* share */)
);
});

Expand All @@ -107,30 +127,47 @@ describe("Reward = 50, 1 miner", function() {
expect(
await node.sdk.rpc.chain.getBalance(faucetAddress)
).to.deep.equal(
FAUCET_INITIAL_CCS.minus(100 /* pay */)
.minus(10 /* fee */)
.plus(7 /* share */)
FAUCET_INITIAL_CCS.minus(100 /* pay */).minus(10 /* fee */)
);
expect(await node.sdk.rpc.chain.getBalance(aliceAddress)).to.deep.equal(
new U64(100 /* pay */).plus(2 /* share */).plus(BLOCK_REWARD)
new U64(100 /* pay */)
.plus(Math.floor((10 * 4) / 10) /* share */)
.plus(BLOCK_REWARD)
);
expect(await node.sdk.rpc.chain.getBalance(bobAddress)).to.deep.equal(
new U64(1 /* share */)
new U64(Math.floor((10 * 3) / 10) /* share */)
);
expect(await node.sdk.rpc.chain.getBalance(carolAddress)).to.deep.equal(
new U64(Math.floor((10 * 2) / 10) /* share */)
);
expect(await node.sdk.rpc.chain.getBalance(daveAddress)).to.deep.equal(
new U64(Math.floor((10 * 1) / 10) /* share */)
);
});

it("Mining a block with a transaction which author pays someone in", async function() {
await node.sendPayTx({ fee: 10 });
expect(
await node.sdk.rpc.chain.getBalance(faucetAddress)
).to.deep.equal(
FAUCET_INITIAL_CCS.minus(10 /* fee */).plus(7 /* share */)
const faucetBalance = await node.sdk.rpc.chain.getBalance(
faucetAddress
);
expect(await node.sdk.rpc.chain.getBalance(aliceAddress)).to.deep.equal(
new U64(2 /* share */).plus(BLOCK_REWARD)
const aliceBalance = await node.sdk.rpc.chain.getBalance(aliceAddress);
const bobBalance = await node.sdk.rpc.chain.getBalance(bobAddress);
const carolBalance = await node.sdk.rpc.chain.getBalance(carolAddress);
const daveBalance = await node.sdk.rpc.chain.getBalance(daveAddress);
expect(faucetBalance).to.deep.equal(
FAUCET_INITIAL_CCS.minus(10 /* fee */)
);
expect(await node.sdk.rpc.chain.getBalance(bobAddress)).to.deep.equal(
new U64(1 /* share */)
expect(aliceBalance).to.deep.equal(
new U64(Math.floor((10 * 4) / 10) /* share */).plus(BLOCK_REWARD)
);
expect(bobBalance).to.deep.equal(
new U64(Math.floor((10 * 3) / 10) /* share */)
);
expect(carolBalance).to.deep.equal(
new U64(Math.floor((10 * 2) / 10) /* share */)
);
expect(daveBalance).to.deep.equal(
new U64(Math.floor((10 * 1) / 10) /* share */)
);

const tx = await node.sdk.core
Expand All @@ -143,22 +180,22 @@ describe("Reward = 50, 1 miner", function() {

expect(
await node.sdk.rpc.chain.getBalance(faucetAddress)
).to.deep.equal(
FAUCET_INITIAL_CCS.minus(10)
.plus(7)
.plus(20 /* pay */)
.plus(7 /* share */)
);
).to.deep.equal(faucetBalance.plus(20 /* pay */));
expect(await node.sdk.rpc.chain.getBalance(aliceAddress)).to.deep.equal(
new U64(2)
.plus(BLOCK_REWARD)
aliceBalance
.minus(20 /* pay */)
.minus(10 /* fee */)
.plus(2 /* share */)
.plus(Math.floor((10 * 4) / 10) /* share */)
.plus(BLOCK_REWARD)
);
expect(await node.sdk.rpc.chain.getBalance(bobAddress)).to.deep.equal(
new U64(1 /* share*/).plus(1 /* share */)
bobBalance.plus(Math.floor((10 * 3) / 10))
);
expect(await node.sdk.rpc.chain.getBalance(carolAddress)).to.deep.equal(
carolBalance.plus(Math.floor((10 * 2) / 10))
);
expect(await node.sdk.rpc.chain.getBalance(daveAddress)).to.deep.equal(
daveBalance.plus(Math.floor((10 * 1) / 10))
);
});

Expand Down
Loading