|
1 | | -import Fixture from "./helpers/Fixture" |
| 1 | +import chai, {assert} from "chai" |
| 2 | +import {solidity} from "ethereum-waffle" |
| 3 | +import {ethers, web3} from "hardhat" |
| 4 | +import {constants} from "../../utils/constants" |
2 | 5 | import { |
3 | 6 | contractId, |
4 | | - functionSig, |
5 | | - functionEncodedABI |
| 7 | + functionEncodedABI, |
| 8 | + functionSig |
6 | 9 | } from "../../utils/helpers" |
7 | | -import expectCheckpoints from "./helpers/expectCheckpoints" |
8 | | -import {constants} from "../../utils/constants" |
9 | 10 | import math from "../helpers/math" |
10 | | -import {assert} from "chai" |
11 | | -import {ethers, web3} from "hardhat" |
| 11 | +import expectCheckpoints from "./helpers/expectCheckpoints" |
| 12 | +import Fixture from "./helpers/Fixture" |
12 | 13 | const BigNumber = ethers.BigNumber |
13 | | -import chai from "chai" |
14 | | -import {solidity} from "ethereum-waffle" |
15 | 14 |
|
16 | 15 | chai.use(solidity) |
17 | 16 | const {expect} = chai |
@@ -1597,6 +1596,235 @@ describe("BondingManager", () => { |
1597 | 1596 | }) |
1598 | 1597 | }) |
1599 | 1598 | }) |
| 1599 | + describe("new delegate is activating on the next round", () => { |
| 1600 | + beforeEach(async () => { |
| 1601 | + await bondingManager |
| 1602 | + .connect(transcoder2) |
| 1603 | + .bond(10000, transcoder2.address) |
| 1604 | + await bondingManager |
| 1605 | + .connect(transcoder2) |
| 1606 | + .transcoder(5, 10) |
| 1607 | + |
| 1608 | + const {activationRound} = |
| 1609 | + await bondingManager.getTranscoder( |
| 1610 | + transcoder2.address |
| 1611 | + ) |
| 1612 | + assert.equal( |
| 1613 | + activationRound, |
| 1614 | + currentRound + 1, |
| 1615 | + "transcoder2 should be activating" |
| 1616 | + ) |
| 1617 | + }) |
| 1618 | + describe("old delegate is active transcoder", () => { |
| 1619 | + it("should not change next total stake", async () => { |
| 1620 | + const startNextTotalStake = |
| 1621 | + await bondingManager.nextRoundTotalActiveStake() |
| 1622 | + await bondingManager |
| 1623 | + .connect(delegator) |
| 1624 | + .bond(0, transcoder2.address) |
| 1625 | + const endNextTotalStake = |
| 1626 | + await bondingManager.nextRoundTotalActiveStake() |
| 1627 | + assert.equal( |
| 1628 | + endNextTotalStake.sub(startNextTotalStake), |
| 1629 | + 0, |
| 1630 | + "wrong change in next total stake" |
| 1631 | + ) |
| 1632 | + }) |
| 1633 | + it("should update transcoder earnings pool", async () => { |
| 1634 | + await bondingManager |
| 1635 | + .connect(delegator) |
| 1636 | + .bond(0, transcoder2.address) |
| 1637 | + const pool = |
| 1638 | + await bondingManager.getTranscoderEarningsPoolForRound( |
| 1639 | + transcoder2.address, |
| 1640 | + currentRound + 1 |
| 1641 | + ) |
| 1642 | + assert.equal( |
| 1643 | + pool.totalStake, |
| 1644 | + 12000, |
| 1645 | + "wrong totalStake in earnings pool" |
| 1646 | + ) |
| 1647 | + }) |
| 1648 | + }) |
| 1649 | + describe("old delegate is not active transcoder", () => { |
| 1650 | + beforeEach(async () => { |
| 1651 | + // Delegate to non-transcoder |
| 1652 | + await bondingManager |
| 1653 | + .connect(delegator) |
| 1654 | + .bond(0, nonTranscoder.address) |
| 1655 | + }) |
| 1656 | + it("should increase next total stake", async () => { |
| 1657 | + const startNextTotalStake = |
| 1658 | + await bondingManager.nextRoundTotalActiveStake() |
| 1659 | + await bondingManager |
| 1660 | + .connect(delegator) |
| 1661 | + .bond(0, transcoder2.address) |
| 1662 | + const endNextTotalStake = |
| 1663 | + await bondingManager.nextRoundTotalActiveStake() |
| 1664 | + assert.equal( |
| 1665 | + endNextTotalStake.sub(startNextTotalStake), |
| 1666 | + 2000, |
| 1667 | + "wrong change in next total stake" |
| 1668 | + ) |
| 1669 | + }) |
| 1670 | + it("should update transcoder earnings pool", async () => { |
| 1671 | + await bondingManager |
| 1672 | + .connect(delegator) |
| 1673 | + .bond(0, transcoder2.address) |
| 1674 | + const pool = |
| 1675 | + await bondingManager.getTranscoderEarningsPoolForRound( |
| 1676 | + transcoder2.address, |
| 1677 | + currentRound + 1 |
| 1678 | + ) |
| 1679 | + assert.equal( |
| 1680 | + pool.totalStake, |
| 1681 | + 12000, |
| 1682 | + "wrong totalStake in earnings pool" |
| 1683 | + ) |
| 1684 | + }) |
| 1685 | + }) |
| 1686 | + }) |
| 1687 | + describe("new delegate is deactivating on the next round", () => { |
| 1688 | + beforeEach(async () => { |
| 1689 | + // add another transcoder so transcoder1 gets kicked out |
| 1690 | + await bondingManager |
| 1691 | + .connect(transcoder2) |
| 1692 | + .bond(10000, transcoder2.address) |
| 1693 | + await bondingManager |
| 1694 | + .connect(transcoder2) |
| 1695 | + .transcoder(5, 10) |
| 1696 | + // bond more on transcoder0 so it doesn't get kicked out when delegator moves |
| 1697 | + await bondingManager |
| 1698 | + .connect(transcoder0) |
| 1699 | + .bond(10000, transcoder0.address) |
| 1700 | + |
| 1701 | + const {deactivationRound} = |
| 1702 | + await bondingManager.getTranscoder( |
| 1703 | + transcoder1.address |
| 1704 | + ) |
| 1705 | + assert.equal( |
| 1706 | + deactivationRound, |
| 1707 | + currentRound + 1, |
| 1708 | + "transcoder1 should be deactivating" |
| 1709 | + ) |
| 1710 | + }) |
| 1711 | + |
| 1712 | + const runTests = () => { |
| 1713 | + describe("old delegate is active transcoder", () => { |
| 1714 | + it("should decrease next total stake", async () => { |
| 1715 | + const startNextTotalStake = |
| 1716 | + await bondingManager.nextRoundTotalActiveStake() |
| 1717 | + await bondingManager |
| 1718 | + .connect(delegator) |
| 1719 | + .bond(0, transcoder1.address) |
| 1720 | + const endNextTotalStake = |
| 1721 | + await bondingManager.nextRoundTotalActiveStake() |
| 1722 | + assert.equal( |
| 1723 | + startNextTotalStake.sub( |
| 1724 | + endNextTotalStake |
| 1725 | + ), |
| 1726 | + 2000, |
| 1727 | + "wrong change in next total stake" |
| 1728 | + ) |
| 1729 | + }) |
| 1730 | + it("should update transcoder earnings pool", async () => { |
| 1731 | + const prevTotalStake = |
| 1732 | + await bondingManager.transcoderTotalStake( |
| 1733 | + transcoder1.address |
| 1734 | + ) |
| 1735 | + await bondingManager |
| 1736 | + .connect(delegator) |
| 1737 | + .bond(0, transcoder1.address) |
| 1738 | + const pool = |
| 1739 | + await bondingManager.getTranscoderEarningsPoolForRound( |
| 1740 | + transcoder1.address, |
| 1741 | + currentRound + 1 |
| 1742 | + ) |
| 1743 | + assert.equal( |
| 1744 | + pool.totalStake |
| 1745 | + .sub(prevTotalStake) |
| 1746 | + .toString(), |
| 1747 | + 2000, |
| 1748 | + "wrong totalStake in earnings pool" |
| 1749 | + ) |
| 1750 | + }) |
| 1751 | + }) |
| 1752 | + describe("old delegate is not active transcoder", () => { |
| 1753 | + beforeEach(async () => { |
| 1754 | + // Delegate to non-transcoder |
| 1755 | + await bondingManager |
| 1756 | + .connect(delegator) |
| 1757 | + .bond(0, nonTranscoder.address) |
| 1758 | + }) |
| 1759 | + it("should not change next total stake", async () => { |
| 1760 | + const startNextTotalStake = |
| 1761 | + await bondingManager.nextRoundTotalActiveStake() |
| 1762 | + await bondingManager |
| 1763 | + .connect(delegator) |
| 1764 | + .bond(0, transcoder1.address) |
| 1765 | + const endNextTotalStake = |
| 1766 | + await bondingManager.nextRoundTotalActiveStake() |
| 1767 | + assert.equal( |
| 1768 | + endNextTotalStake.sub( |
| 1769 | + startNextTotalStake |
| 1770 | + ), |
| 1771 | + 0, |
| 1772 | + "wrong change in next total stake" |
| 1773 | + ) |
| 1774 | + }) |
| 1775 | + it("should update transcoder earnings pool", async () => { |
| 1776 | + const prevTotalStake = |
| 1777 | + await bondingManager.transcoderTotalStake( |
| 1778 | + transcoder1.address |
| 1779 | + ) |
| 1780 | + await bondingManager |
| 1781 | + .connect(delegator) |
| 1782 | + .bond(0, transcoder1.address) |
| 1783 | + const pool = |
| 1784 | + await bondingManager.getTranscoderEarningsPoolForRound( |
| 1785 | + transcoder1.address, |
| 1786 | + currentRound + 1 |
| 1787 | + ) |
| 1788 | + assert.equal( |
| 1789 | + pool.totalStake |
| 1790 | + .sub(prevTotalStake) |
| 1791 | + .toString(), |
| 1792 | + 2000, |
| 1793 | + "wrong totalStake in earnings pool" |
| 1794 | + ) |
| 1795 | + }) |
| 1796 | + }) |
| 1797 | + } |
| 1798 | + |
| 1799 | + describe("delegate is registered transcoder", () => { |
| 1800 | + runTests() |
| 1801 | + }) |
| 1802 | + |
| 1803 | + describe("delegate is not registered transcoder", () => { |
| 1804 | + beforeEach(async () => { |
| 1805 | + // additionally, unbond the entire self-bond so it becomes a non registered T |
| 1806 | + await bondingManager |
| 1807 | + .connect(transcoder1) |
| 1808 | + .unbond(2000) |
| 1809 | + |
| 1810 | + // double-check it's still active but not registered |
| 1811 | + assert.isTrue( |
| 1812 | + await bondingManager.isActiveTranscoder( |
| 1813 | + transcoder1.address |
| 1814 | + ), |
| 1815 | + "transcoder1 should be active" |
| 1816 | + ) |
| 1817 | + assert.isFalse( |
| 1818 | + await bondingManager.isRegisteredTranscoder( |
| 1819 | + transcoder1.address |
| 1820 | + ), |
| 1821 | + "transcoder1 should not be registered" |
| 1822 | + ) |
| 1823 | + }) |
| 1824 | + |
| 1825 | + runTests() |
| 1826 | + }) |
| 1827 | + }) |
1600 | 1828 | describe("old delegate is registered transcoder", () => { |
1601 | 1829 | it("should decrease transcoder's total stake in pool by current bonded stake", async () => { |
1602 | 1830 | const startTranscoderTotalStake = |
|
0 commit comments