public void Fail_to_register_existing_domain() { var settings = chain.GetProtocolSettings(); var alice = chain.GetDefaultAccount("alice").ToScriptHash(settings.AddressVersion); var bob = chain.GetDefaultAccount("bob").ToScriptHash(settings.AddressVersion); using var snapshot = fixture.GetSnapshot(); var domainOwners = snapshot.GetContractStorages <Registrar>().StorageMap(DOMAIN_OWNERS_PREFIX); domainOwners.TryGetValue(DOMAIN_NAME, out var item).Should().BeTrue(); item !.Should().Be(bob); using var engine = new TestApplicationEngine(snapshot, settings, alice); using var monitor = engine.Monitor(); engine.ExecuteScript <Registrar>(c => c.register(DOMAIN_NAME, alice)); if (engine.State != VMState.HALT) { output.WriteLine($"FaultException: {engine.FaultException}"); } monitor.Should().Raise("Log") .WithSender(engine) .WithArgs <LogEventArgs>(args => args.Message == "Domain already registered"); engine.State.Should().Be(VMState.HALT); engine.ResultStack.Should().HaveCount(1); engine.ResultStack.Peek(0).Should().BeFalse(); }
public void contract_owner_in_storage() { var settings = chain.GetProtocolSettings(); var owner = chain.GetDefaultAccount("owner").ToScriptHash(settings.AddressVersion); using var snapshot = fixture.GetSnapshot(); var storages = snapshot.GetContractStorages <SafePurchase>(); storages.Count().Should().Be(1); storages.TryGetValue(new byte[] { 0xff }, out var item).Should().BeTrue(); item !.Should().Be(owner); }
public void contract_owner_in_storage() { var settings = chain.GetProtocolSettings(); var owen = chain.GetDefaultAccount("owen").ToScriptHash(settings.AddressVersion); using var snapshot = fixture.GetSnapshot(); // check to make sure contract owner stored in contract storage var storages = snapshot.GetContractStorages <Registrar>(); storages.Count().Should().Be(1); storages.TryGetValue(CONTRACT_OWNER_PREFIX, out var item).Should().BeTrue(); item !.Should().Be(owen); }
public void seller_has_9900_neo() { var settings = chain.GetProtocolSettings(); var seller = chain.GetDefaultAccount("seller").ToScriptHash(settings.AddressVersion); using var builder = new ScriptBuilder(); builder.EmitContractCall <Nep17Token>(NativeContracts.NeoToken, c => c.balanceOf(seller)); using var snapshot = fixture.GetSnapshot(); using var engine = new TestApplicationEngine(snapshot, settings, seller); engine.ExecuteScript(builder.ToArray()); engine.State.Should().Be(VMState.HALT); engine.ResultStack.Should().HaveCount(1); engine.ResultStack.Peek(0).Should().BeEquivalentTo(9900); }
public void Can_register_domain() { var settings = chain.GetProtocolSettings(); var alice = chain.GetDefaultAccount("alice").ToScriptHash(settings.AddressVersion); using var snapshot = fixture.GetSnapshot(); // pretest check to ensure storage is empty as expected snapshot.GetContractStorages <Registrar>().Any().Should().BeFalse(); // ExecuteScript converts the provided expression(s) into a Neo script // loads them into the engine and executes it using var engine = new TestApplicationEngine(snapshot, settings, alice); var logs = new List <string>(); engine.Log += (sender, args) => { logs.Add(args.Message); }; engine.ExecuteScript <Registrar>(c => c.register(DOMAIN_NAME, alice)); engine.State.Should().Be(VMState.HALT); engine.ResultStack.Should().HaveCount(1); engine.ResultStack.Peek(0).Should().BeTrue(); // ensure correct storage item was created var storages = snapshot.GetContractStorages <Registrar>(); storages.TryGetValue(DOMAIN_NAME_BYTES, out var item).Should().BeTrue(); item !.Should().Be(alice); }
public ExpressChainManager(IFileSystem fileSystem, ExpressChain chain, uint?secondsPerBlock = null) { this.fileSystem = fileSystem; this.chain = chain; uint secondsPerBlockResult = secondsPerBlock.HasValue ? secondsPerBlock.Value : chain.TryReadSetting <uint>("chain.SecondsPerBlock", uint.TryParse, out var secondsPerBlockSetting) ? secondsPerBlockSetting : 0; this.ProtocolSettings = chain.GetProtocolSettings(secondsPerBlockResult); }
public static bool TryGetAccountHash(this ExpressChain chain, string name, [MaybeNullWhen(false)] out UInt160 accountHash, ProtocolSettings?settings = null) { settings ??= chain.GetProtocolSettings(); if (chain.Wallets != null && chain.Wallets.Count > 0) { for (int i = 0; i < chain.Wallets.Count; i++) { if (string.Equals(name, chain.Wallets[i].Name, StringComparison.OrdinalIgnoreCase)) { var wallet = DevWallet.FromExpressWallet(settings, chain.Wallets[i]); var account = wallet.GetAccounts().Single(a => a.IsDefault); accountHash = account.ScriptHash; return(true); } } } Debug.Assert(chain.ConsensusNodes != null && chain.ConsensusNodes.Count > 0); for (int i = 0; i < chain.ConsensusNodes.Count; i++) { var nodeWallet = chain.ConsensusNodes[i].Wallet; if (string.Equals(name, nodeWallet.Name, StringComparison.OrdinalIgnoreCase)) { var wallet = DevWallet.FromExpressWallet(settings, nodeWallet); var account = wallet.GetAccounts().Single(a => a.IsDefault); accountHash = account.ScriptHash; return(true); } } if (GENESIS.Equals(name, StringComparison.OrdinalIgnoreCase)) { (_, accountHash) = chain.GetGenesisAccount(settings); return(true); } if (TryToScriptHash(name, settings.AddressVersion, out accountHash)) { return(true); } accountHash = default; return(false);
public ExpressChainManager(IFileSystem fileSystem, ExpressChain chain, uint secondsPerBlock) { this.fileSystem = fileSystem; this.chain = chain; this.ProtocolSettings = chain.GetProtocolSettings(secondsPerBlock); }