public void uitnSerializationTests2() { var v = new uint256("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20"); var vr = new uint256("201f1e1d1c1b1a191817161514131211100f0e0d0c0b0a090807060504030201"); var bytes = v.ToBytes(); Assert.Equal(0x20, bytes[0]); Assert.Equal(0x01, bytes[31]); var v2 = new uint256(bytes); Assert.Equal(v, v2); Assert.Equal("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20", v2.ToString()); var bytes2 = new byte[32]; v2.ToBytes(bytes2); var v3 = new uint256(bytes2, 0, 32); Assert.Equal(v2, v3); Assert.Equal(vr, new uint256(v.ToBytes(false))); v.ToBytes(bytes, false); Assert.Equal(vr, new uint256(bytes)); v.ToBytes(bytes); Assert.Equal(vr, new uint256(bytes, false)); Assert.Equal(v, new uint256(Enumerable.Range(0, 32).Select(i => v.GetByte(i)).ToArray())); Assert.Equal(0x1d1e1f20U, v.GetLow32()); Assert.Equal(0x191a1b1c1d1e1f20U, v.GetLow64()); }
public void TransactionCreated(int cycleId, TransactionType type, uint256 txId, CorrelationId correlation) { var record = new TrackerRecord() { Cycle = cycleId, RecordType = RecordType.Transaction, TransactionType = type, TransactionId = txId, Correlation = correlation, }; bool isNew = true; _Repo.UpdateOrInsert(GetCyclePartition(cycleId), txId.GetLow64().ToString(), record, (a, b) => { isNew = false; return(b); }); _Repo.UpdateOrInsert("Search", "t:" + txId.ToString(), cycleId, (a, b) => b); if (isNew) { Logs.Tracker.LogInformation($"Tracking transaction {type} of cycle {cycleId} with correlation {correlation} ({txId})"); } }
public void methods() { Assert.True(R1L.GetHex() == R1L.ToString()); Assert.True(R2L.GetHex() == R2L.ToString()); Assert.True(OneL.GetHex() == OneL.ToString()); Assert.True(MaxL.GetHex() == MaxL.ToString()); uint256 TmpL = new uint256(R1L); Assert.True(TmpL == R1L); TmpL.SetHex(R2L.ToString()); Assert.True(TmpL == R2L); TmpL.SetHex(ZeroL.ToString()); Assert.True(TmpL == 0); TmpL.SetHex(HalfL.ToString()); Assert.True(TmpL == HalfL); TmpL.SetHex(R1L.ToString()); AssertEx.CollectionEquals(R1L.ToBytes(), R1Array); AssertEx.CollectionEquals(TmpL.ToBytes(), R1Array); AssertEx.CollectionEquals(R2L.ToBytes(), R2Array); AssertEx.CollectionEquals(ZeroL.ToBytes(), ZeroArray); AssertEx.CollectionEquals(OneL.ToBytes(), OneArray); Assert.True(R1L.Size == 32); Assert.True(R2L.Size == 32); Assert.True(ZeroL.Size == 32); Assert.True(MaxL.Size == 32); //No sense in .NET //Assert.True(R1L.begin() + 32 == R1L.end()); //Assert.True(R2L.begin() + 32 == R2L.end()); //Assert.True(OneL.begin() + 32 == OneL.end()); //Assert.True(MaxL.begin() + 32 == MaxL.end()); //Assert.True(TmpL.begin() + 32 == TmpL.end()); Assert.True(R1L.GetLow64() == R1LLow64); Assert.True(HalfL.GetLow64() == 0x0000000000000000UL); Assert.True(OneL.GetLow64() == 0x0000000000000001UL); Assert.True(R1L.GetSerializeSize(0, ProtocolVersion.PROTOCOL_VERSION) == 32); Assert.True(ZeroL.GetSerializeSize(0, ProtocolVersion.PROTOCOL_VERSION) == 32); MemoryStream ss = new MemoryStream(); R1L.Serialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION); Assert.True(ArrayToString(ss.ToArray()) == ArrayToString(R1Array)); TmpL.Unserialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION); Assert.True(R1L == TmpL); ss = new MemoryStream(); ZeroL.Serialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION); Assert.True(ArrayToString(ss.ToArray()) == ArrayToString(ZeroArray)); ss.Position = 0; TmpL.Unserialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION); Assert.True(ZeroL == TmpL); ss = new MemoryStream(); MaxL.Serialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION); Assert.True(ArrayToString(ss.ToArray()) == ArrayToString(MaxArray)); ss.Position = 0; TmpL.Unserialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION); Assert.True(MaxL == TmpL); ss = new MemoryStream(); Assert.True(R1S.GetHex() == R1S.ToString()); Assert.True(R2S.GetHex() == R2S.ToString()); Assert.True(OneS.GetHex() == OneS.ToString()); Assert.True(MaxS.GetHex() == MaxS.ToString()); uint160 TmpS = new uint160(R1S); Assert.True(TmpS == R1S); TmpS.SetHex(R2S.ToString()); Assert.True(TmpS == R2S); TmpS.SetHex(ZeroS.ToString()); Assert.True(TmpS == 0); TmpS.SetHex(HalfS.ToString()); Assert.True(TmpS == HalfS); TmpS.SetHex(R1S.ToString()); Assert.True(ArrayToString(R1S.ToBytes()) == ArrayToString(R1Array.Take(20).ToArray())); Assert.True(ArrayToString(TmpS.ToBytes()) == ArrayToString(R1Array.Take(20).ToArray())); Assert.True(ArrayToString(R2S.ToBytes()) == ArrayToString(R2Array.Take(20).ToArray())); Assert.True(ArrayToString(ZeroS.ToBytes()) == ArrayToString(ZeroArray.Take(20).ToArray())); Assert.True(ArrayToString(OneS.ToBytes()) == ArrayToString(OneArray.Take(20).ToArray())); Assert.True(R1S.Size == 20); Assert.True(R2S.Size == 20); Assert.True(ZeroS.Size == 20); Assert.True(MaxS.Size == 20); //No sense in .NET //Assert.True(R1S.begin() + 20 == R1S.end()); //Assert.True(R2S.begin() + 20 == R2S.end()); //Assert.True(OneS.begin() + 20 == OneS.end()); //Assert.True(MaxS.begin() + 20 == MaxS.end()); //Assert.True(TmpS.begin() + 20 == TmpS.end()); Assert.True(R1S.GetLow64() == R1LLow64); Assert.True(HalfS.GetLow64() == 0x0000000000000000UL); Assert.True(OneS.GetLow64() == 0x0000000000000001UL); Assert.True(R1S.GetSerializeSize(0, ProtocolVersion.PROTOCOL_VERSION) == 20); Assert.True(ZeroS.GetSerializeSize(0, ProtocolVersion.PROTOCOL_VERSION) == 20); R1S.Serialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION); Assert.True(ArrayToString(ss.ToArray()) == ArrayToString(R1Array.Take(20).ToArray())); ss.Position = 0; TmpS.Unserialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION); Assert.True(R1S == TmpS); ss = new MemoryStream(); ZeroS.Serialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION); Assert.True(ArrayToString(ss.ToArray()) == ArrayToString(ZeroArray.Take(20).ToArray())); ss.Position = 0; TmpS.Unserialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION); Assert.True(ZeroS == TmpS); ss = new MemoryStream(); MaxS.Serialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION); Assert.True(ArrayToString(ss.ToArray()) == ArrayToString(MaxArray.Take(20).ToArray())); ss.Position = 0; TmpS.Unserialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION); Assert.True(MaxS == TmpS); ss = new MemoryStream(); //for(int i = 0 ; i < 255 ; ++i) //{ // Assert.True((OneL << i).GetDouble() == Math.Pow(1.0, i)); // if(i < 160) // Assert.True((OneS << i).GetDouble() == Math.Pow(1.0, i)); //} //Assert.True(ZeroL.GetDouble() == 0.0); //Assert.True(ZeroS.GetDouble() == 0.0); //for(int i = 256 ; i > 53 ; --i) // Assert.True(almostEqual((R1L >> (256 - i)).GetDouble(), Math.Pow(R1Ldouble, i))); //for(int i = 160 ; i > 53 ; --i) // Assert.True(almostEqual((R1S >> (160 - i)).GetDouble(), Math.Pow(R1Sdouble, i))); //ulong R1L64part = (R1L >> 192).GetLow64(); //ulong R1S64part = (R1S >> 96).GetLow64(); //for(int i = 53 ; i > 0 ; --i) // doubles can store all integers in {0,...,2^54-1} exactly //{ // Assert.True((R1L >> (256 - i)).GetDouble() == (double)(R1L64part >> (64 - i))); // Assert.True((R1S >> (160 - i)).GetDouble() == (double)(R1S64part >> (64 - i))); //} }