UBots local tests setup

1.Create ubot registry contract for your local config by running code below:


 >>> int N = 2; // UBOTS COUNT

    @Ignore
    @Test
    public void createUBotRegistryContractAndSave() throws Exception {
        Contract contract = new Contract(TestKeys.privateKey(1));

        List<Binder> topology = new ArrayList<>();
        ListRole listRole = new ListRole("ubots",contract);
        listRole.setMode(ListRole.Mode.ALL);

        for(int i = 0;i < N;i++) {
            int number = i;
            PublicKey publicKey = new PublicKey(Do.read("./src/ubot_config/ubot0/config/keys/ubot_"+i+".public.unikey"));
            listRole.addRole(new SimpleRole("ubot"+number,contract,Do.listOf(publicKey.getLongAddress())));
            topology.add(Binder.of(
                    "number",number,
                    "key", Base64u.encodeString(publicKey.pack()),
                    "domain_urls",Do.listOf("https://localhost:"+(17000+i)),
                    "direct_urls",Do.listOf("http://127.0.0.1:"+(17000+i))
            ));
        }

        contract.addRole(listRole);
        contract.getStateData().put("topology",topology);
        contract.seal();

        new FileOutputStream("ubot_registry_contract.unicon").write(contract.getLastSealedBinary());

    }

2.Run:

cp ./universa_node/ubot_registry_contract.unicon ./docker/compose/deploy/config/

3.Edit ./docker/compose/docker-compose.yaml (8 differences in total):

  • Change "universa/node:latest" to "universa/node:unstable" 4 times.
  • Add "- ./deploy/config/ubot_registry_contract.unicon:/deploy/config/contracts/ubot_registry_contract.unicon" after "- ./deploy/config/shared.yaml:/deploy/config/shared.yaml" 4 times.

4.Add to Config.java:


    uIssuerKeys.add(new KeyAddress("JTu6iMHtQ5GeDxN6WMeRArS8YRFWN7aTRiue6XUqPgGayUHDn3qZwFfHe9KafmQhUUvZcVRY"));
    addressesWhiteList.add(new KeyAddress("JTu6iMHtQ5GeDxN6WMeRArS8YRFWN7aTRiue6XUqPgGayUHDn3qZwFfHe9KafmQhUUvZcVRY"));
    uIssuerKeys.add(new KeyAddress("ZyKzyzCf95CHZ1is11oWWWoDgd7GRZ7By17tF5itp5EXfm9uSz"));
    addressesWhiteList.add(new KeyAddress("ZyKzyzCf95CHZ1is11oWWWoDgd7GRZ7By17tF5itp5EXfm9uSz"));

5.Run:

docker build --tag universa/node:unstable --compress -f docker/node/Dockerfile .

6.To start local network, run:

docker-compose -p docker -f docker/compose/docker-compose.yaml up -d

7.Run:

cp docker/compose/universa.local.json ~/.universa/topology/

8.Run:

cp docker/compose/universa.local.json $U8_REPO/test/config/ubot_config/ubot0/config/mainnet_topology.json 

(for every ubot you have) ubot0,ubot1,ubot2 etc.

cp docker/compose/universa.local.json $U8_REPO/jslib/ubot/topology/mainnet_topology.json

9.Register created ubot registry by running code below:

    @Ignore
    @Test
    public void registerUBotRegistryContract() throws Exception {
        Client client = new Client("universa.local",null,TestKeys.privateKey(0));
        Contract ubotRegistry =  Contract.fromPackedTransaction(client.getServiceContracts().getBinaryOrThrow("ubot_registry_contract"));
        System.out.println(client.register(ubotRegistry.getPackedTransaction(),10000));
    }

10.Run your ubots with universa.local as host network.

11.To stop local network, run:

docker-compose -p docker -f docker/compose/docker-compose.yaml down