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/>.
|
|
|
|
|
2018-07-17 21:23:07 +00:00
|
|
|
package history_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
|
2019-05-17 04:15:54 +00:00
|
|
|
"math/big"
|
|
|
|
|
2020-01-29 19:00:07 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/eth/fakes"
|
2020-01-30 22:35:31 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/eth/history"
|
2018-07-17 21:23:07 +00:00
|
|
|
)
|
|
|
|
|
2018-07-20 16:37:46 +00:00
|
|
|
var _ = Describe("Validation window", func() {
|
2018-07-17 21:23:07 +00:00
|
|
|
It("creates a ValidationWindow equal to (HEAD-windowSize, HEAD)", func() {
|
2018-07-20 16:37:46 +00:00
|
|
|
blockChain := fakes.NewMockBlockChain()
|
|
|
|
blockChain.SetLastBlock(big.NewInt(5))
|
|
|
|
|
2019-02-14 15:04:12 +00:00
|
|
|
validationWindow, err := history.MakeValidationWindow(blockChain, 2)
|
2018-07-17 21:23:07 +00:00
|
|
|
|
2019-02-14 15:04:12 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-07-17 21:23:07 +00:00
|
|
|
Expect(validationWindow.LowerBound).To(Equal(int64(3)))
|
|
|
|
Expect(validationWindow.UpperBound).To(Equal(int64(5)))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("returns the window size", func() {
|
|
|
|
window := history.ValidationWindow{LowerBound: 1, UpperBound: 3}
|
|
|
|
|
|
|
|
Expect(window.Size()).To(Equal(2))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("generates a range of int64s", func() {
|
|
|
|
numberOfBlocksCreated := history.MakeRange(0, 5)
|
|
|
|
expected := []int64{0, 1, 2, 3, 4, 5}
|
|
|
|
|
|
|
|
Expect(numberOfBlocksCreated).To(Equal(expected))
|
|
|
|
})
|
|
|
|
})
|