Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Stratis.Bitcoin.Features.PoA/PoAConsensusOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public class PoAConsensusOptions : ConsensusOptions
/// </summary>
public int PollExpiryBlocks { get; set; }

/// <summary>
/// Defines when V2 of the contract serializer will be used.
/// I.e if tip <= ContractSerializerV2ActivationHeight, V1 will be used.
/// </summary>
public int ContractSerializerV2ActivationHeight { get; set; }

/// <summary>Initializes values for networks that use block size rules.</summary>
public PoAConsensusOptions(
uint maxBlockBaseSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public struct TestLog
public void Deserialize_Basic_Log_Success()
{
var network = new SmartContractsRegTest();
var primitiveSerializer = new ContractPrimitiveSerializer(network);
var primitiveSerializer = new ContractPrimitiveSerializerV2(network);

var testStruct = new TestLog
{
Expand Down Expand Up @@ -68,7 +68,7 @@ public void Deserialize_Basic_Log_Success()
public void Deserialize_Logs_With_Different_Addresses_From_Cache()
{
var network = new SmartContractsRegTest();
var primitiveSerializer = new ContractPrimitiveSerializer(network);
var primitiveSerializer = new ContractPrimitiveSerializerV2(network);

var testStruct0 = new TestLog
{
Expand Down Expand Up @@ -119,7 +119,7 @@ public void Deserialize_Logs_With_Different_Addresses_From_Cache()
public void MapTransferInfo_Success()
{
var network = new SmartContractsRegTest();
var primitiveSerializer = new ContractPrimitiveSerializer(network);
var primitiveSerializer = new ContractPrimitiveSerializerV2(network);

var stateRoot = new Mock<IStateRepositoryRoot>();
stateRoot.Setup(r => r.GetCodeHash(It.IsAny<uint160>())).Returns(uint256.Zero.ToBytes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ContractValidationRuleTest
public ContractValidationRuleTest()
{
this.network = new SmartContractsRegTest();
this.callDataSerializer = new CallDataSerializer(new ContractPrimitiveSerializer(this.network));
this.callDataSerializer = new CallDataSerializer(new ContractPrimitiveSerializerV2(this.network));
}

private UnspentOutputSet GetMockOutputSet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static TestRulesContext CreateAsync(Network network, [CallerMemberName] s
testRulesContext.ChainIndexer, deployments, consensusSettings, testRulesContext.Checkpoints, null, testRulesContext.ChainState,
new InvalidBlockHashStore(new DateTimeProvider()), new NodeStats(testRulesContext.DateTimeProvider, testRulesContext.NodeSettings, new Mock<IVersionProvider>().Object), testRulesContext.AsyncProvider, new ConsensusRulesContainer()).SetupRulesEngineParent();

testRulesContext.CallDataSerializer = new CallDataSerializer(new ContractPrimitiveSerializer(network));
testRulesContext.CallDataSerializer = new CallDataSerializer(new ContractPrimitiveSerializerV2(network));
return testRulesContext;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Stratis.Sidechains.Networks/CirrusMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ public CirrusMain()
InterFluxV2MainChainActivationHeight = 460_000,
VotingManagerV2ActivationHeight = 1_683_000, // Tuesday, 12 January 2021 9:00:00 AM (Estimated)
Release1100ActivationHeight = 3_426_950, // Monday, 20 December 2021 10:00:00 AM (Estimated)
PollExpiryBlocks = 50_000 // Roughly 9 days
PollExpiryBlocks = 50_000, // Roughly 9 days
ContractSerializerV2ActivationHeight = 3364000
};

var buriedDeployments = new BuriedDeploymentsArray
Expand Down
3 changes: 2 additions & 1 deletion src/Stratis.Sidechains.Networks/CirrusTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ public CirrusTest()
EnforcedMinProtocolVersion = ProtocolVersion.CIRRUS_VERSION, // minimum protocol version which will be enforced at block height defined in EnforceMinProtocolVersionAtBlockHeight
VotingManagerV2ActivationHeight = 1_999_500,
Release1100ActivationHeight = 2_796_000,
PollExpiryBlocks = 450 // 2 hours
PollExpiryBlocks = 450, // 2 hours
ContractSerializerV2ActivationHeight = 2842681
};

var buriedDeployments = new BuriedDeploymentsArray
Expand Down
2 changes: 1 addition & 1 deletion src/Stratis.SmartContracts.CLR.Tests/AuctionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public AuctionTests()
};
var getBalance = new Func<ulong>(() => Balance);
var persistentState = new TestPersistentState();
var serializer = new Serializer(new ContractPrimitiveSerializer(network));
var serializer = new Serializer(new ContractPrimitiveSerializerV2(network));
this.smartContractState = new TestSmartContractState(
block,
message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Stratis.SmartContracts.CLR.Tests
{
public sealed class CallDataSerializerTests
{
public ICallDataSerializer Serializer = new CallDataSerializer(new ContractPrimitiveSerializer(new SmartContractsRegTest()));
public ICallDataSerializer Serializer = new CallDataSerializer(new ContractPrimitiveSerializerV2(new SmartContractsRegTest()));

[Fact]
public void SmartContract_CanSerialize_OP_CREATECONTRACT_WithoutMethodParameters()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ContractExecutorTestContext()
this.KeyEncodingStrategy = BasicKeyEncodingStrategy.Default;
this.LoggerFactory = ExtendedLoggerFactory.Create();
this.State = new StateRepositoryRoot(new NoDeleteSource<byte[], byte[]>(new MemoryDictionarySource()));
this.ContractPrimitiveSerializer = new ContractPrimitiveSerializer(this.Network);
this.ContractPrimitiveSerializer = new ContractPrimitiveSerializerV2(this.Network);
this.Serializer = new Serializer(this.ContractPrimitiveSerializer);
this.AddressGenerator = new AddressGenerator();
this.Validator = new SmartContractValidator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ContractExecutorTests()
this.addressGenerator = new AddressGenerator();
this.assemblyLoader = new ContractAssemblyLoader();
this.moduleDefinitionReader = new ContractModuleDefinitionReader();
this.contractPrimitiveSerializer = new ContractPrimitiveSerializer(this.network);
this.contractPrimitiveSerializer = new ContractPrimitiveSerializerV2(this.network);
this.serializer = new Serializer(this.contractPrimitiveSerializer);
this.contractCache = new ContractAssemblyCache();
this.vm = new ReflectionVirtualMachine(this.validator, this.loggerFactory, this.assemblyLoader, this.moduleDefinitionReader, this.contractCache);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ContractLogHolderTests
public ContractLogHolderTests()
{
this.network = new SmartContractsRegTest();
this.serializer = new ContractPrimitiveSerializer(this.network);
this.serializer = new ContractPrimitiveSerializerV2(this.network);
this.logHolder = new ContractLogHolder();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using NBitcoin;
using Stratis.SmartContracts.CLR.Serialization;
using Stratis.SmartContracts.Networks;
using Xunit;

namespace Stratis.SmartContracts.CLR.Tests
{
public class ContractPrimitiveSerializerV1Tests
{
private readonly IContractPrimitiveSerializer serializer;
private readonly Network network;

public ContractPrimitiveSerializerV1Tests()
{
this.network = new SmartContractsRegTest();
this.serializer = new ContractPrimitiveSerializerV1(this.network);
}

[Fact]
public void Test_ReferenceType_Serialization()
{
Assert.Null(this.serializer.Deserialize(typeof(string), this.serializer.Serialize("")));
Assert.Null(this.serializer.Deserialize(typeof(byte[]), this.serializer.Serialize(new byte[0])));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

namespace Stratis.SmartContracts.CLR.Tests
{
public class ContractPrimitiveSerializerTests
public class ContractPrimitiveSerializerV2Tests
{
private readonly ContractPrimitiveSerializer serializer;
private readonly IContractPrimitiveSerializer serializer;
private readonly Network network;

public ContractPrimitiveSerializerTests()
public ContractPrimitiveSerializerV2Tests()
{
this.network = new SmartContractsRegTest();
this.serializer = new ContractPrimitiveSerializer(this.network);
this.serializer = new ContractPrimitiveSerializerV2(this.network);
}

[Fact]
Expand Down Expand Up @@ -173,6 +173,13 @@ public void Deserialize_Empty_Byte_Array()
Assert.True(emptyByte.SequenceEqual(this.serializer.Deserialize<byte[]>(empty)));
}

[Fact]
public void Test_ReferenceType_Serialization()
{
Assert.Equal("", this.serializer.Deserialize(typeof(string), this.serializer.Serialize("")));
Assert.Equal(new byte[0], this.serializer.Deserialize(typeof(byte[]), this.serializer.Serialize(new byte[0])));
}

private TestValueType NewTestValueType()
{
var instance = new TestValueType();
Expand Down
2 changes: 1 addition & 1 deletion src/Stratis.SmartContracts.CLR.Tests/Logs/RawLogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Example(string name, uint amount)
[Fact]
public void RawLog_With_Null_Value_Serializes()
{
var serializer = new ContractPrimitiveSerializer(new SmartContractsPoARegTest());
var serializer = new ContractPrimitiveSerializerV2(new SmartContractsPoARegTest());
var exampleLog = new Example(null, 0);

var rawLog = new RawLog(uint160.One, exampleLog);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Stratis.SmartContracts.CLR.Tests
public class MethodParameterByteSerializerTests
{
public static Network Network = new SmartContractsPoARegTest();
public IMethodParameterSerializer Serializer = new MethodParameterByteSerializer(new ContractPrimitiveSerializer(Network));
public IMethodParameterSerializer Serializer = new MethodParameterByteSerializer(new ContractPrimitiveSerializerV2(Network));

[Theory]
[MemberData(nameof(GetData), parameters: 1)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public ObserverInstanceRewriterTests()
var getBalance = new Func<ulong>(() => Balance);
var persistentState = new TestPersistentState();
var network = new SmartContractsRegTest();
var serializer = new ContractPrimitiveSerializer(network);
var serializer = new ContractPrimitiveSerializerV2(network);
this.state = new SmartContractState(
new Block(1, this.TestAddress),
new Message(this.TestAddress, this.TestAddress, 0),
Expand Down
2 changes: 1 addition & 1 deletion src/Stratis.SmartContracts.CLR.Tests/ObserverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public ObserverTests()
var getBalance = new Func<ulong>(() => Balance);
var persistentState = new TestPersistentState();
var network = new SmartContractsRegTest();
var serializer = new ContractPrimitiveSerializer(network);
var serializer = new ContractPrimitiveSerializerV2(network);
this.state = new SmartContractState(
new Block(1, this.TestAddress),
new Message(this.TestAddress, this.TestAddress, 0),
Expand Down
2 changes: 1 addition & 1 deletion src/Stratis.SmartContracts.CLR.Tests/SerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public void SingleByteStringSerializesCorrectly()
{
const string test = "1";

var testSerializer = new Serializer(new ContractPrimitiveSerializer(new SmartContractsPoARegTest()));
var testSerializer = new Serializer(new ContractPrimitiveSerializerV2(new SmartContractsPoARegTest()));

byte[] bytes = testSerializer.Serialize(test);

Expand Down
Loading