2018-11-07 21:50:43 +00:00
|
|
|
// VulcanizeDB
|
2019-03-12 15:46:42 +00:00
|
|
|
// Copyright © 2019 Vulcanize
|
2018-11-07 21:50:43 +00:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-12-27 23:51:17 +00:00
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
2018-07-18 20:59:40 +00:00
|
|
|
"github.com/ethereum/go-ethereum/ethclient"
|
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
2017-12-27 23:51:17 +00:00
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2018-07-20 16:37:46 +00:00
|
|
|
|
2019-10-28 11:30:24 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/eth"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/eth/client"
|
|
|
|
vRpc "github.com/vulcanize/vulcanizedb/pkg/eth/converters/rpc"
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/eth/node"
|
2018-02-13 16:31:57 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/test_config"
|
2017-12-27 23:51:17 +00:00
|
|
|
)
|
|
|
|
|
2017-12-28 16:06:13 +00:00
|
|
|
var _ = Describe("Rewards calculations", func() {
|
2017-12-27 23:51:17 +00:00
|
|
|
|
2017-12-28 16:06:13 +00:00
|
|
|
It("calculates a block reward for a real block", func() {
|
2019-10-18 16:16:19 +00:00
|
|
|
rawRPCClient, err := rpc.Dial(test_config.TestClient.IPCPath)
|
2018-07-18 20:59:40 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2019-10-18 16:16:19 +00:00
|
|
|
rpcClient := client.NewRPCClient(rawRPCClient, test_config.TestClient.IPCPath)
|
|
|
|
ethClient := ethclient.NewClient(rawRPCClient)
|
2018-07-20 16:37:46 +00:00
|
|
|
blockChainClient := client.NewEthClient(ethClient)
|
|
|
|
node := node.MakeNode(rpcClient)
|
2019-10-18 16:16:19 +00:00
|
|
|
transactionConverter := vRpc.NewRPCTransactionConverter(ethClient)
|
2019-10-28 11:30:24 +00:00
|
|
|
blockChain := eth.NewBlockChain(blockChainClient, rpcClient, node, transactionConverter)
|
2018-07-18 20:59:40 +00:00
|
|
|
block, err := blockChain.GetBlockByNumber(1071819)
|
2018-03-27 21:06:12 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2019-03-22 03:43:06 +00:00
|
|
|
Expect(block.Reward).To(Equal("5313550000000000000"))
|
2017-12-28 16:06:13 +00:00
|
|
|
})
|
2017-12-27 23:51:17 +00:00
|
|
|
|
2017-12-28 16:06:13 +00:00
|
|
|
It("calculates an uncle reward for a real block", func() {
|
2019-10-18 16:16:19 +00:00
|
|
|
rawRPCClient, err := rpc.Dial(test_config.TestClient.IPCPath)
|
2018-07-18 20:59:40 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2019-10-18 16:16:19 +00:00
|
|
|
rpcClient := client.NewRPCClient(rawRPCClient, test_config.TestClient.IPCPath)
|
|
|
|
ethClient := ethclient.NewClient(rawRPCClient)
|
2018-07-20 16:37:46 +00:00
|
|
|
blockChainClient := client.NewEthClient(ethClient)
|
|
|
|
node := node.MakeNode(rpcClient)
|
2019-10-18 16:16:19 +00:00
|
|
|
transactionConverter := vRpc.NewRPCTransactionConverter(ethClient)
|
2019-10-28 11:30:24 +00:00
|
|
|
blockChain := eth.NewBlockChain(blockChainClient, rpcClient, node, transactionConverter)
|
2018-07-18 20:59:40 +00:00
|
|
|
block, err := blockChain.GetBlockByNumber(1071819)
|
2018-03-27 21:06:12 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2019-03-22 03:43:06 +00:00
|
|
|
Expect(block.UnclesReward).To(Equal("6875000000000000000"))
|
2017-12-27 23:51:17 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
})
|