ouroboros-network-mock
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Network.Mock.ConcreteBlock

Description

Concrete block

The network library should not export a concrete block type at all, except that it might need one in its tests (but not exported). Right now this module serves to isolate this in a specific module so we can identify easily where it is used; eventually it should be simplified and then moved to the network layer tests; the more sophiscated block abstraction (abstracted over an Ouroboros protocol) will live in the consensus layer.

Synopsis

Documentation

data Block Source #

Our highly-simplified version of a block. It retains the separation between a block header and body, which is a detail needed for the protocols.

Constructors

Block 

Instances

Instances details
Generic Block Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Associated Types

type Rep Block 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

type Rep Block = D1 ('MetaData "Block" "Ouroboros.Network.Mock.ConcreteBlock" "ouroboros-network-mock-0.1.1.2-inplace" 'False) (C1 ('MetaCons "Block" 'PrefixI 'True) (S1 ('MetaSel ('Just "blockHeader") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 BlockHeader) :*: S1 ('MetaSel ('Just "blockBody") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 BlockBody)))

Methods

from :: Block -> Rep Block x #

to :: Rep Block x -> Block #

Show Block Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Methods

showsPrec :: Int -> Block -> ShowS #

show :: Block -> String #

showList :: [Block] -> ShowS #

Eq Block Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Methods

(==) :: Block -> Block -> Bool #

(/=) :: Block -> Block -> Bool #

HasFullHeader Block Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

HasHeader Block Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Serialise Block Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

StandardHash Block Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

ShowProxy Block Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

type Rep Block Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

type Rep Block = D1 ('MetaData "Block" "Ouroboros.Network.Mock.ConcreteBlock" "ouroboros-network-mock-0.1.1.2-inplace" 'False) (C1 ('MetaCons "Block" 'PrefixI 'True) (S1 ('MetaSel ('Just "blockHeader") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 BlockHeader) :*: S1 ('MetaSel ('Just "blockBody") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 BlockBody)))
type HeaderHash Block Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

data BlockHeader Source #

A block header. It retains simplified versions of all the essential elements.

Constructors

BlockHeader 

Fields

Instances

Instances details
Generic BlockHeader Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Associated Types

type Rep BlockHeader 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

type Rep BlockHeader = D1 ('MetaData "BlockHeader" "Ouroboros.Network.Mock.ConcreteBlock" "ouroboros-network-mock-0.1.1.2-inplace" 'False) (C1 ('MetaCons "BlockHeader" 'PrefixI 'True) ((S1 ('MetaSel ('Just "headerHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (HeaderHash BlockHeader)) :*: S1 ('MetaSel ('Just "headerPrevHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (ChainHash BlockHeader))) :*: (S1 ('MetaSel ('Just "headerSlot") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 SlotNo) :*: (S1 ('MetaSel ('Just "headerBlockNo") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 BlockNo) :*: S1 ('MetaSel ('Just "headerBodyHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 BodyHash)))))
Show BlockHeader Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Eq BlockHeader Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

HasFullHeader BlockHeader Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

HasHeader BlockHeader Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Serialise BlockHeader Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

StandardHash BlockHeader Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

ShowProxy BlockHeader Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

type Rep BlockHeader Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

type Rep BlockHeader = D1 ('MetaData "BlockHeader" "Ouroboros.Network.Mock.ConcreteBlock" "ouroboros-network-mock-0.1.1.2-inplace" 'False) (C1 ('MetaCons "BlockHeader" 'PrefixI 'True) ((S1 ('MetaSel ('Just "headerHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (HeaderHash BlockHeader)) :*: S1 ('MetaSel ('Just "headerPrevHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (ChainHash BlockHeader))) :*: (S1 ('MetaSel ('Just "headerSlot") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 SlotNo) :*: (S1 ('MetaSel ('Just "headerBlockNo") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 BlockNo) :*: S1 ('MetaSel ('Just "headerBodyHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 BodyHash)))))
type HeaderHash BlockHeader Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

newtype BlockBody Source #

Constructors

BlockBody ByteString 

Instances

Instances details
IsString BlockBody Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Generic BlockBody Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Associated Types

type Rep BlockBody 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

type Rep BlockBody = D1 ('MetaData "BlockBody" "Ouroboros.Network.Mock.ConcreteBlock" "ouroboros-network-mock-0.1.1.2-inplace" 'True) (C1 ('MetaCons "BlockBody" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))
Show BlockBody Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Eq BlockBody Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Ord BlockBody Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Hashable BlockBody Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Serialise BlockBody Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

type Rep BlockBody Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

type Rep BlockBody = D1 ('MetaData "BlockBody" "Ouroboros.Network.Mock.ConcreteBlock" "ouroboros-network-mock-0.1.1.2-inplace" 'True) (C1 ('MetaCons "BlockBody" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

newtype BodyHash Source #

The hash of all the information in a BlockBody.

Constructors

BodyHash Int 

Instances

Instances details
Generic BodyHash Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Associated Types

type Rep BodyHash 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

type Rep BodyHash = D1 ('MetaData "BodyHash" "Ouroboros.Network.Mock.ConcreteBlock" "ouroboros-network-mock-0.1.1.2-inplace" 'True) (C1 ('MetaCons "BodyHash" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))

Methods

from :: BodyHash -> Rep BodyHash x #

to :: Rep BodyHash x -> BodyHash #

Show BodyHash Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Eq BodyHash Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Ord BodyHash Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Hashable BodyHash Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Methods

hashWithSalt :: Int -> BodyHash -> Int #

hash :: BodyHash -> Int #

Serialise BodyHash Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

type Rep BodyHash Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

type Rep BodyHash = D1 ('MetaData "BodyHash" "Ouroboros.Network.Mock.ConcreteBlock" "ouroboros-network-mock-0.1.1.2-inplace" 'True) (C1 ('MetaCons "BodyHash" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))

newtype ConcreteHeaderHash Source #

The hash of all the information in a BlockHeader.

Constructors

HeaderHash Int 

Instances

Instances details
Generic ConcreteHeaderHash Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Associated Types

type Rep ConcreteHeaderHash 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

type Rep ConcreteHeaderHash = D1 ('MetaData "ConcreteHeaderHash" "Ouroboros.Network.Mock.ConcreteBlock" "ouroboros-network-mock-0.1.1.2-inplace" 'True) (C1 ('MetaCons "HeaderHash" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))
Show ConcreteHeaderHash Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Eq ConcreteHeaderHash Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Ord ConcreteHeaderHash Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Hashable ConcreteHeaderHash Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

NoThunks ConcreteHeaderHash Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

Serialise ConcreteHeaderHash Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

type Rep ConcreteHeaderHash Source # 
Instance details

Defined in Ouroboros.Network.Mock.ConcreteBlock

type Rep ConcreteHeaderHash = D1 ('MetaData "ConcreteHeaderHash" "Ouroboros.Network.Mock.ConcreteBlock" "ouroboros-network-mock-0.1.1.2-inplace" 'True) (C1 ('MetaCons "HeaderHash" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))

hashBody :: Hashable body => body -> BodyHash Source #

Converting slots to times

convertSlotToTimeForTestsAssumingNoHardFork :: SlotNo -> UTCTime Source #

Arbitrarily but consistently converts slots UTCTimes.

It is only intended for use in tests. Notably it assumes a fixed system start time, slot length, and the absence of a hard fork (ie no HardForkCombinator). This is how it's available as a pure function.

Creating sample chains

mkChain :: [(SlotNo, BlockBody)] -> Chain Block Source #

This takes the blocks in order from oldest to newest.

Generator utilities

fixupBlock :: HeaderHash block ~ HeaderHash BlockHeader => Anchor block -> Block -> Block Source #

Fix up a block so that it fits on top of the given anchor. Only the block number, the previous hash and the block hash are updated; the slot number and the signers are kept intact.

fixupBlockHeader :: HeaderHash block ~ HeaderHash BlockHeader => Anchor block -> BlockHeader -> BlockHeader Source #

Fixup block header to fit it on top of a chain. Only block number and previous hash are updated; the slot and signer are kept unchanged.

fixupBlockAfterBlock :: Block -> Block -> Block Source #

Fixup a block so to fit it on top of a given previous block.

fixupChain :: HasFullHeader b => (Anchor b -> b -> b) -> [b] -> Chain b Source #

Fix up the block number and hashes of a Chain. This also fixes up the first block to chain-on from genesis, since by construction the Chain type starts from genesis.

Orphan instances

Hashable BlockNo Source # 
Instance details

Methods

hashWithSalt :: Int -> BlockNo -> Int #

hash :: BlockNo -> Int #

Hashable SlotNo Source # 
Instance details

Methods

hashWithSalt :: Int -> SlotNo -> Int #

hash :: SlotNo -> Int #

(StandardHash b, Hashable (HeaderHash b)) => Hashable (ChainHash b) Source #

Hashable instance for Hash

We don't insist that Hashable in StandardHash because Hashable is only used in the network layer tests.

This requires UndecidableInstances because Hashable (HeaderHash b) is no smaller than Hashable (ChainHash b).

Instance details

Methods

hashWithSalt :: Int -> ChainHash b -> Int #

hash :: ChainHash b -> Int #