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); }