notary = Notary()

guardiankey = newsigner(notary)
registratorkey = newsigner(notary)

member1key = newsigner(notary)
member2key = newsigner(notary)
member3key = newsigner(notary)


guardian = Guardian(id(guardiankey))
registrator = Registrator(id(registratorkey))
member1 = Member(id(member1key))
member2 = Member(id(member2key))
member3 = Member(id(member3key))


transactions = TransactionVector()
tlog = BraidChain(transactions, guardian, notary)

push!(tlog, Transaction(member1, guardiankey))
Test.@test_throws AssertionError push!(tlog, Transaction(member2, registratorkey))
push!(tlog, Transaction(registrator, guardiankey))
push!(tlog, Transaction(member2, registratorkey))
Test.@test_throws AssertionError push!(tlog, Transaction(member2, registratorkey))

pseudonyms(tlog, 3)


### Braiders 

braider = Braider(ID(1332))
push!(tlog, Transaction(braider, guardiankey))


m = MetaData(ID(2323), braider.id, Hash(tlog))

pseudonym1 = newsigner(notary)
pseudonym2 = newsigner(notary)
pseudonym3 = newsigner(notary)

# generated by users
newpseudonyms = ID[id(pseudonym1), id(pseudonym2), id(pseudonym3)]

thisbraid = SynchronicBraid(m, newpseudonyms)


contract = Contract(Dict[Dict(sign(thisbraid, member1key)), Dict(sign(thisbraid, member2key)), Dict(sign(thisbraid, member3key))])


Test.@test_throws AssertionError push!(tlog, Transaction(thisbraid, contract)) ### Should throw an error

push!(tlog, Transaction(member3, registratorkey))
push!(tlog, Transaction(thisbraid, contract)) ### Should throw an error


### New BraidChain

bcnew = BraidChain(tlog.transactions, guardian, notary)
@test pseudonyms(tlog) == pseudonyms(bcnew)
