Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

[SC] Upgrade to Stratis.SmartContracts 1.2.1 #3262

Merged
merged 7 commits into from
Mar 4, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Stratis.SmartContracts.CLR;
using Stratis.SmartContracts.CLR.Serialization;
using Stratis.SmartContracts.Networks;
using Stratis.SmartContracts.RuntimeObserver;
using Xunit;

namespace Stratis.Bitcoin.Features.SmartContracts.Tests.Consensus.Rules
Expand Down Expand Up @@ -72,7 +73,7 @@ public async Task SmartContractFormatRule_SuccessAsync()

var totalSuppliedSatoshis = gasBudgetSatoshis + relayFeeSatoshis;

var contractTxData = new ContractTxData(1, (ulong)gasPriceSatoshis, (Stratis.SmartContracts.RuntimeObserver.Gas)gasLimit, 0, "TestMethod");
var contractTxData = new ContractTxData(1, (ulong)gasPriceSatoshis, (Gas)gasLimit, 0, "TestMethod");
var serialized = this.callDataSerializer.Serialize(contractTxData);

Transaction funding = new Transaction
Expand Down Expand Up @@ -119,7 +120,7 @@ public async Task SmartContractFormatRule_MultipleOutputs_SuccessAsync()

var totalSuppliedSatoshis = gasBudgetSatoshis + relayFeeSatoshis;

var contractTxData = new ContractTxData(1, (ulong)gasPriceSatoshis, (Stratis.SmartContracts.RuntimeObserver.Gas)gasLimit, 0, "TestMethod");
var contractTxData = new ContractTxData(1, (ulong)gasPriceSatoshis, (Gas)gasLimit, 0, "TestMethod");
var serialized = this.callDataSerializer.Serialize(contractTxData);

Transaction funding = new Transaction
Expand Down Expand Up @@ -170,7 +171,7 @@ public async Task SmartContractFormatRule_FailureAsync()

var higherGasLimit = gasLimit + 10000;

var contractTxData = new ContractTxData(1, (ulong)gasPriceSatoshis, (Stratis.SmartContracts.RuntimeObserver.Gas)higherGasLimit, 0, "TestMethod");
var contractTxData = new ContractTxData(1, (ulong)gasPriceSatoshis, (Gas)higherGasLimit, 0, "TestMethod");
var serialized = this.callDataSerializer.Serialize(contractTxData);

Transaction funding = new Transaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Stratis.SmartContracts.CLR;
using Stratis.SmartContracts.CLR.Serialization;
using Stratis.SmartContracts.Networks;
using Stratis.SmartContracts.RuntimeObserver;
using Xunit;

namespace Stratis.Bitcoin.Features.SmartContracts.Tests.Controllers
Expand Down Expand Up @@ -49,7 +50,7 @@ public void GetHistoryWithValidModelWithoutTransactionSpendingDetailsReturnsWall
{
ulong gasPrice = SmartContractMempoolValidator.MinGasPrice;
int vmVersion = 1;
var gasLimit = (Stratis.SmartContracts.RuntimeObserver.Gas)(SmartContractFormatLogic.GasLimitMaximum / 2);
var gasLimit = (Gas)(SmartContractFormatLogic.GasLimitMaximum / 2);
var contractTxData = new ContractTxData(vmVersion, gasPrice, gasLimit, new byte[]{0, 1, 2, 3});
var callDataSerializer = new CallDataSerializer(new ContractPrimitiveSerializer(new SmartContractsRegTest()));
var contractCreateScript = new Script(callDataSerializer.Serialize(contractTxData));
Expand Down Expand Up @@ -94,7 +95,7 @@ public void GetHistoryWithValidModelWithoutTransactionSpendingDetailsReturnsWall
this.receiptRepository.Setup(x => x.Retrieve(It.IsAny<uint256>()))
.Returns(new Receipt(null, 0, new Log[0], null, null, null, uint160.Zero, true, null, null));
this.callDataSerializer.Setup(x => x.Deserialize(It.IsAny<byte[]>()))
.Returns(Result.Ok(new ContractTxData(0, 0, (Stratis.SmartContracts.RuntimeObserver.Gas) 0, new uint160(0), null, null)));
.Returns(Result.Ok(new ContractTxData(0, 0, (Gas) 0, new uint160(0), null, null)));

var controller = new SmartContractWalletController(
this.broadcasterManager.Object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Stratis.SmartContracts" Version="1.1.0" />
<PackageReference Include="Stratis.SmartContracts" Version="1.2.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

<ItemGroup>
<PackageReference Include="CSharpFunctionalExtensions" Version="1.10.0" />
<PackageReference Include="Stratis.SmartContracts" Version="1.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Stratis.SmartContracts.CLR.Serialization;
using Stratis.SmartContracts.Core;
using Stratis.SmartContracts.Core.ContractSigning;
using Stratis.SmartContracts.RuntimeObserver;

namespace Stratis.Bitcoin.Features.SmartContracts.Wallet
{
Expand Down Expand Up @@ -63,7 +64,7 @@ public BuildCallContractTransactionResponse BuildCallTx(BuildCallContractTransac
try
{
object[] methodParameters = this.methodParameterStringSerializer.Deserialize(request.Parameters);
txData = new ContractTxData(ReflectionVirtualMachine.VmVersion, (Stratis.SmartContracts.RuntimeObserver.Gas)request.GasPrice, (Stratis.SmartContracts.RuntimeObserver.Gas)request.GasLimit, addressNumeric, request.MethodName, methodParameters);
txData = new ContractTxData(ReflectionVirtualMachine.VmVersion, (Gas)request.GasPrice, (Gas)request.GasLimit, addressNumeric, request.MethodName, methodParameters);
}
catch (MethodParameterStringSerializerException exception)
{
Expand All @@ -72,7 +73,7 @@ public BuildCallContractTransactionResponse BuildCallTx(BuildCallContractTransac
}
else
{
txData = new ContractTxData(ReflectionVirtualMachine.VmVersion, (Stratis.SmartContracts.RuntimeObserver.Gas)request.GasPrice, (Stratis.SmartContracts.RuntimeObserver.Gas)request.GasLimit, addressNumeric, request.MethodName);
txData = new ContractTxData(ReflectionVirtualMachine.VmVersion, (Gas)request.GasPrice, (Gas)request.GasLimit, addressNumeric, request.MethodName);
}

HdAddress senderAddress = null;
Expand Down Expand Up @@ -124,7 +125,7 @@ public BuildCreateContractTransactionResponse BuildCreateTx(BuildCreateContractT
try
{
object[] methodParameters = this.methodParameterStringSerializer.Deserialize(request.Parameters);
txData = new ContractTxData(ReflectionVirtualMachine.VmVersion, (Stratis.SmartContracts.RuntimeObserver.Gas)request.GasPrice, (Stratis.SmartContracts.RuntimeObserver.Gas)request.GasLimit, request.ContractCode.HexToByteArray(), methodParameters);
txData = new ContractTxData(ReflectionVirtualMachine.VmVersion, (Gas)request.GasPrice, (Gas)request.GasLimit, request.ContractCode.HexToByteArray(), methodParameters);
}
catch (MethodParameterStringSerializerException exception)
{
Expand All @@ -133,7 +134,7 @@ public BuildCreateContractTransactionResponse BuildCreateTx(BuildCreateContractT
}
else
{
txData = new ContractTxData(ReflectionVirtualMachine.VmVersion, (Stratis.SmartContracts.RuntimeObserver.Gas)request.GasPrice, (Stratis.SmartContracts.RuntimeObserver.Gas)request.GasLimit, request.ContractCode.HexToByteArray());
txData = new ContractTxData(ReflectionVirtualMachine.VmVersion, (Gas)request.GasPrice, (Gas)request.GasLimit, request.ContractCode.HexToByteArray());
}

HdAddress senderAddress = null;
Expand Down Expand Up @@ -205,10 +206,10 @@ public ContractTxData BuildLocalCallTxData(LocalCallContractRequest request)
{
object[] methodParameters = this.methodParameterStringSerializer.Deserialize(request.Parameters);

return new ContractTxData(ReflectionVirtualMachine.VmVersion, (Stratis.SmartContracts.RuntimeObserver.Gas)request.GasPrice, (Stratis.SmartContracts.RuntimeObserver.Gas)request.GasLimit, contractAddress, request.MethodName, methodParameters);
return new ContractTxData(ReflectionVirtualMachine.VmVersion, (Gas)request.GasPrice, (Gas)request.GasLimit, contractAddress, request.MethodName, methodParameters);
}

return new ContractTxData(ReflectionVirtualMachine.VmVersion, (Stratis.SmartContracts.RuntimeObserver.Gas)request.GasPrice, (Stratis.SmartContracts.RuntimeObserver.Gas)request.GasLimit, contractAddress, request.MethodName);
return new ContractTxData(ReflectionVirtualMachine.VmVersion, (Gas)request.GasPrice, (Gas)request.GasLimit, contractAddress, request.MethodName);
}

}
Expand Down
1 change: 1 addition & 0 deletions src/Stratis.SmartContracts.CLR.Tests/AuctionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using Stratis.SmartContracts.CLR.Serialization;
using Stratis.SmartContracts.Networks;
using Stratis.SmartContracts.RuntimeObserver;
using Xunit;

namespace Stratis.SmartContracts.CLR.Tests
Expand Down
13 changes: 7 additions & 6 deletions src/Stratis.SmartContracts.CLR.Tests/CallDataSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Stratis.SmartContracts.CLR.Serialization;
using Stratis.SmartContracts.Core;
using Stratis.SmartContracts.Networks;
using Stratis.SmartContracts.RuntimeObserver;
using Xunit;

namespace Stratis.SmartContracts.CLR.Tests
Expand All @@ -29,16 +30,16 @@ public void TestMethod()
}"
);

var contractTxData = new ContractTxData(1, 1, (RuntimeObserver.Gas)5000, contractExecutionCode);
var contractTxData = new ContractTxData(1, 1, (Gas)5000, contractExecutionCode);
var callDataResult = this.Serializer.Deserialize(this.Serializer.Serialize(contractTxData));
var callData = callDataResult.Value;

Assert.True((bool) callDataResult.IsSuccess);
Assert.Equal(1, callData.VmVersion);
Assert.Equal((byte)ScOpcodeType.OP_CREATECONTRACT, callData.OpCodeType);
Assert.Equal<byte[]>(contractExecutionCode, callData.ContractExecutionCode);
Assert.Equal((RuntimeObserver.Gas)1, callData.GasPrice);
Assert.Equal((RuntimeObserver.Gas)5000, callData.GasLimit);
Assert.Equal((Gas)1, callData.GasPrice);
Assert.Equal((Gas)5000, callData.GasLimit);
}

[Fact]
Expand Down Expand Up @@ -68,7 +69,7 @@ public void TestMethod(int orders, bool canOrder)
'#'
};

var contractTxData = new ContractTxData(1, 1, (RuntimeObserver.Gas)5000, contractExecutionCode, methodParameters);
var contractTxData = new ContractTxData(1, 1, (Gas)5000, contractExecutionCode, methodParameters);

var callDataResult = this.Serializer.Deserialize(this.Serializer.Serialize(contractTxData));
var callData = callDataResult.Value;
Expand Down Expand Up @@ -101,7 +102,7 @@ public void TestMethod(int orders, bool canOrder)
[Fact]
public void SmartContract_CanSerialize_OP_CALLCONTRACT_WithoutMethodParameters()
{
var contractTxData = new ContractTxData(1, 1, (RuntimeObserver.Gas)5000, 100, "Execute");
var contractTxData = new ContractTxData(1, 1, (Gas)5000, 100, "Execute");

var callDataResult = this.Serializer.Deserialize(this.Serializer.Serialize(contractTxData));
var callData = callDataResult.Value;
Expand Down Expand Up @@ -131,7 +132,7 @@ public void SmartContract_CanSerialize_OP_CALLCONTRACT_WithMethodParameters()
"0x95D34980095380851902ccd9A1Fb4C813C2cb639".HexToAddress()
};

var contractTxData = new ContractTxData(1, 1, (RuntimeObserver.Gas)5000, 100, "Execute", methodParameters);
var contractTxData = new ContractTxData(1, 1, (Gas)5000, 100, "Execute", methodParameters);
var callDataResult = this.Serializer.Deserialize(this.Serializer.Serialize(contractTxData));
var callData = callDataResult.Value;

Expand Down
23 changes: 12 additions & 11 deletions src/Stratis.SmartContracts.CLR.Tests/ContractExecutorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Stratis.SmartContracts.Core;
using Stratis.SmartContracts.Core.State;
using Stratis.SmartContracts.Networks;
using Stratis.SmartContracts.RuntimeObserver;
using Xunit;

namespace Stratis.SmartContracts.CLR.Tests
Expand Down Expand Up @@ -76,7 +77,7 @@ public void SmartContractExecutor_CallContract_Fails_ReturnFundsToSender()


//Call smart contract and add to transaction-------------
var contractTxData = new ContractTxData(1, 1, (RuntimeObserver.Gas)500_000, ToAddress, "ThrowException");
var contractTxData = new ContractTxData(1, 1, (Gas)500_000, ToAddress, "ThrowException");
var transactionCall = new Transaction();
TxOut callTxOut = transactionCall.AddOutput(0, new Script(this.callDataSerializer.Serialize(contractTxData)));
callTxOut.Value = 100;
Expand Down Expand Up @@ -114,7 +115,7 @@ public void SmartContractExecutor_CallContract_Fails_ReturnFundsToSender()
[Fact]
public void SmartContractExecutor_CallContract_DoesNotExist_Refund()
{
var contractTxData = new ContractTxData(1, 1, (RuntimeObserver.Gas) 10000, ToAddress, "TestMethod");
var contractTxData = new ContractTxData(1, 1, (Gas) 10000, ToAddress, "TestMethod");

var transaction = new Transaction();
TxOut txOut = transaction.AddOutput(0, new Script(this.callDataSerializer.Serialize(contractTxData)));
Expand Down Expand Up @@ -142,7 +143,7 @@ public void SME_CreateContract_ConstructorFails_Refund()
Assert.True(compilationResult.Success);
byte[] contractCode = compilationResult.Compilation;

var contractTxData = new ContractTxData(0, (RuntimeObserver.Gas) 1, (RuntimeObserver.Gas)500_000, contractCode);
var contractTxData = new ContractTxData(0, (Gas) 1, (Gas)500_000, contractCode);
var tx = new Transaction();
tx.AddOutput(0, new Script(this.callDataSerializer.Serialize(contractTxData)));

Expand Down Expand Up @@ -173,7 +174,7 @@ public void SME_CreateContract_MethodParameters_InvalidParameterCount()

object[] methodParameters = { 5 };

var contractTxData = new ContractTxData(0, (RuntimeObserver.Gas)1, (RuntimeObserver.Gas)500_000, contractCode, methodParameters);
var contractTxData = new ContractTxData(0, (Gas)1, (Gas)500_000, contractCode, methodParameters);
var tx = new Transaction();
tx.AddOutput(0, new Script(this.callDataSerializer.Serialize(contractTxData)));

Expand Down Expand Up @@ -202,7 +203,7 @@ public void SME_CreateContract_MethodParameters_ParameterTypeMismatch()

object[] methodParameters = { true };

var contractTxData = new ContractTxData(0, (RuntimeObserver.Gas)1, (RuntimeObserver.Gas)500_000, contractCode, methodParameters);
var contractTxData = new ContractTxData(0, (Gas)1, (Gas)500_000, contractCode, methodParameters);
var tx = new Transaction();
tx.AddOutput(0, new Script(this.callDataSerializer.Serialize(contractTxData)));

Expand Down Expand Up @@ -235,7 +236,7 @@ public void Execute_InterContractCall_Internal_InfiniteLoop_Fails()
//-------------------------------------------------------

// Add contract creation code to transaction-------------
var contractTxData = new ContractTxData(1, (RuntimeObserver.Gas)1, (RuntimeObserver.Gas)500_000, contractExecutionCode);
var contractTxData = new ContractTxData(1, (Gas)1, (Gas)500_000, contractExecutionCode);
var transaction = new Transaction();
TxOut txOut = transaction.AddOutput(0, new Script(this.callDataSerializer.Serialize(contractTxData)));
txOut.Value = 100;
Expand Down Expand Up @@ -269,7 +270,7 @@ public void Execute_InterContractCall_Internal_InfiniteLoop_Fails()
//-------------------------------------------------------

//Call smart contract and add to transaction-------------
contractTxData = new ContractTxData(1, (RuntimeObserver.Gas)1, (RuntimeObserver.Gas)500_000, contractExecutionCode);
contractTxData = new ContractTxData(1, (Gas)1, (Gas)500_000, contractExecutionCode);
transaction = new Transaction();
txOut = transaction.AddOutput(0, new Script(this.callDataSerializer.Serialize(contractTxData)));
txOut.Value = 100;
Expand All @@ -287,11 +288,11 @@ public void Execute_InterContractCall_Internal_InfiniteLoop_Fails()

// Invoke infinite loop

var gasLimit = (RuntimeObserver.Gas)500_000;
var gasLimit = (Gas)500_000;

object[] parameters = { address1.ToAddress() };

contractTxData = new ContractTxData(1, (RuntimeObserver.Gas)1, gasLimit, address2, "CallInfiniteLoop", parameters);
contractTxData = new ContractTxData(1, (Gas)1, gasLimit, address2, "CallInfiniteLoop", parameters);
transaction = new Transaction();
txOut = transaction.AddOutput(0, new Script(this.callDataSerializer.Serialize(contractTxData)));
txOut.Value = 100;
Expand Down Expand Up @@ -348,7 +349,7 @@ private void AssertSuccessfulContractMethodExecution(string contractName, string
Assert.True(compilationResult.Success);
byte[] contractExecutionCode = compilationResult.Compilation;

var contractTxData = new ContractTxData(1, (RuntimeObserver.Gas)1, (RuntimeObserver.Gas)500_000, contractExecutionCode);
var contractTxData = new ContractTxData(1, (Gas)1, (Gas)500_000, contractExecutionCode);

var transaction = new Transaction();
TxOut txOut = transaction.AddOutput(0, new Script(this.callDataSerializer.Serialize(contractTxData)));
Expand All @@ -358,7 +359,7 @@ private void AssertSuccessfulContractMethodExecution(string contractName, string
IContractExecutionResult result = executor.Execute(transactionContext);
uint160 contractAddress = result.NewContractAddress;

contractTxData = new ContractTxData(1, (RuntimeObserver.Gas)1, (RuntimeObserver.Gas)500_000, contractAddress, methodName, methodParameters);
contractTxData = new ContractTxData(1, (Gas)1, (Gas)500_000, contractAddress, methodName, methodParameters);

transaction = new Transaction();
txOut = transaction.AddOutput(0, new Script(this.callDataSerializer.Serialize(contractTxData)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Stratis.SmartContracts.CLR.Local;
using Stratis.SmartContracts.Core;
using Stratis.SmartContracts.Networks;
using Stratis.SmartContracts.RuntimeObserver;
using Xunit;

namespace Stratis.SmartContracts.CLR.Tests
Expand Down Expand Up @@ -43,7 +44,7 @@ public void LocalExecutionResult_Outputs_With_Address()
var execResult = new LocalExecutionResult
{
ErrorMessage = new ContractErrorMessage("Error message"),
GasConsumed = (RuntimeObserver.Gas) 69,
GasConsumed = (Gas) 69,
Return = testAddress
};

Expand Down
Loading