How can I make some variables persist between various test scenarious in diorama?

In one I create an Entity:

  //global variable. Is this a good way in Diorama?
  var addr1 = "some_addr";

  diorama.registerScenario("create 123", async (s, t, {alice}) => {
      let res1 = await alice.call("my_app", "create_my_entity", {"name": "broker1"});
      t.deepEqual(res1, {Ok: addr1}, "create 123'");
      t.ok(res1, res1.Ok !== undefined && res1.Err === undefined);
    
      // All ok
  })

In the other test I try to retrieve an entity I created previously:

  diorama.registerScenario("retrieve 123", async (s, t, {alice}) => {
      let res1 = await alice.call("my_app", "get_my_entity", {addr: addr1});
      


      //Error -> HashNotFound
      t.deepEqual(res1, {Ok: "aabbcc"}, "retrieve 123'");
  })

The entity wan’t found. I suppose that it’s been destroyed after the 1st step. How make it persist?

@alx normally we try very hard to avoid anything at all persisting across tests

some testing frameworks even randomise the ordering of tests to help detect violations of this principle :slight_smile:

the idea is that we want to be able to (ideally deterministically) build up everything we need in order to test a specific set of inputs and corresponding outputs

if you have some specific test fixtures you need then you could write a function that returns and/or builds what you need in the state?

1 Like