Example #1
0
        public BadContractTests()
        {
            StateProvider = GetRequiredService <IStateProviderFactory>().CreateStateProvider();
            BridgeContext = GetRequiredService <IHostSmartContractBridgeContextService>().Create();

            var transactionContext = new TransactionContext()
            {
                Transaction = new Transaction()
                {
                    From = SampleAddress.AddressList[0],
                    To   = SampleAddress.AddressList[1]
                }
            };

            BridgeContext.TransactionContext = transactionContext;

            Contract.InternalInitialize(BridgeContext);

            var injectedCounter = Contract.GetType().Assembly
                                  .GetTypes().SingleOrDefault(t => t.Name == nameof(ExecutionObserverProxy));

            injectedCounter.ShouldNotBeNull();

            _proxyCountMethod = injectedCounter.GetMethod(nameof(ExecutionObserverProxy.SetObserver), new[] { typeof(IExecutionObserver) });
            _proxyCountMethod.ShouldNotBeNull();
        }
        private IHostSmartContractBridgeContext CreateNewContext()
        {
            _bridgeContext = GetRequiredService <IHostSmartContractBridgeContext>();

            var transactionContext = new TransactionContext()
            {
                Transaction = new Transaction()
                {
                    From           = Address.FromPublicKey(_keyPair.PublicKey),
                    To             = SampleAddress.AddressList[0],
                    MethodName     = "Test",
                    Params         = ByteString.CopyFrom(new byte[10]),
                    RefBlockNumber = 1,
                    RefBlockPrefix = ByteString.CopyFrom(new byte[4])
                },
                BlockHeight       = 3,
                CurrentBlockTime  = TimestampHelper.GetUtcNow(),
                PreviousBlockHash = Hash.Empty,
                Trace             = new TransactionTrace(),
                StateCache        = new NullStateCache()
            };
            var signature = CryptoHelper.SignWithPrivateKey(_keyPair.PrivateKey, transactionContext.Transaction
                                                            .GetHash().ToByteArray());

            transactionContext.Transaction.Signature = ByteString.CopyFrom(signature);
            _bridgeContext.Initialize(transactionContext);

            return(_bridgeContext);
        }
Example #3
0
 public HostSmartContractBridgeContextTests()
 {
     _blockchainService               = GetRequiredService <IBlockchainService>();
     _smartContractAddressService     = GetRequiredService <ISmartContractAddressService>();
     _defaultContractZeroCodeProvider = GetRequiredService <IDefaultContractZeroCodeProvider>();
     _keyPair       = CryptoHelpers.GenerateKeyPair();
     _bridgeContext = CreateNewContext();
 }
Example #4
0
        public TestContractTests()
        {
            StateProvider = GetRequiredService <IStateProviderFactory>().CreateStateProvider();
            BridgeContext = GetRequiredService <IHostSmartContractBridgeContextService>().Create();

            var transactionContext = new TransactionContext()
            {
                Transaction = new Transaction()
                {
                    From = SampleAddress.AddressList[0],
                    To   = SampleAddress.AddressList[1]
                }
            };

            BridgeContext.TransactionContext = transactionContext;

            Contract.InternalInitialize(BridgeContext);
        }
Example #5
0
        public ContractTest()
        {
            StateProvider = GetRequiredService <IStateProviderFactory>().CreateStateProvider();
            BridgeContext = GetRequiredService <IHostSmartContractBridgeContextService>().Create();
            Contract.InternalInitialize(BridgeContext);
            //Contract.SetStateProvider(StateProvider);

            var transactionContext = new TransactionContext()
            {
                Transaction = new Transaction()
                {
                    From = AddressList[1],
                    To   = AddressList[0]
                }
            };

            BridgeContext.TransactionContext = transactionContext;
            //StateProvider.TransactionContext = transactionContext;
        }
Example #6
0
 public IExecutive SetHostSmartContractBridgeContext(IHostSmartContractBridgeContext smartContractBridgeContext)
 {
     _hostSmartContractBridgeContext = smartContractBridgeContext;
     _smartContractProxy.InternalInitialize(_hostSmartContractBridgeContext);
     return(this);
 }
Example #7
0
 public MethodStubFactory(IHostSmartContractBridgeContext context)
 {
     _context = context;
 }