aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-09-18 17:23:31 +0800
committerFelix Lange <fjl@twurst.com>2015-09-18 17:23:31 +0800
commit216c486a3aef2c4e7b4c1dc37b14d321ce912723 (patch)
tree22b76ce6718d2c2d1ff15c8486951e013602420c /core
parentac6248ed7ade7aca68b7d09aee5d4ecc9f420c55 (diff)
parent6f3cb12924a87525026c814078ebf3a7f9cb0acb (diff)
downloaddexon-216c486a3aef2c4e7b4c1dc37b14d321ce912723.tar.gz
dexon-216c486a3aef2c4e7b4c1dc37b14d321ce912723.tar.zst
dexon-216c486a3aef2c4e7b4c1dc37b14d321ce912723.zip
Merge pull request #1815 from karalabe/chain-maker-timer
core: allow modifying test-chain block times
Diffstat (limited to 'core')
-rw-r--r--core/chain_makers.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/core/chain_makers.go b/core/chain_makers.go
index d3b7c42b6..70233438d 100644
--- a/core/chain_makers.go
+++ b/core/chain_makers.go
@@ -131,6 +131,17 @@ func (b *BlockGen) PrevBlock(index int) *types.Block {
return b.chain[index]
}
+// OffsetTime modifies the time instance of a block, implicitly changing its
+// associated difficulty. It's useful to test scenarios where forking is not
+// tied to chain length directly.
+func (b *BlockGen) OffsetTime(seconds int64) {
+ b.header.Time.Add(b.header.Time, new(big.Int).SetInt64(seconds))
+ if b.header.Time.Cmp(b.parent.Header().Time) <= 0 {
+ panic("block time out of range")
+ }
+ b.header.Difficulty = CalcDifficulty(b.header.Time.Uint64(), b.parent.Time().Uint64(), b.parent.Number(), b.parent.Difficulty())
+}
+
// GenerateChain creates a chain of n blocks. The first block's
// parent will be the provided parent. db is used to store
// intermediate states and should contain the parent's state trie.