Shigoto-dev19 / ZK-Battleships-Solana

First decentralized & private Battleships game on Solana. Honorable Mention recognition in Solana Grizzlython Hackathon
https://solana.com/news/solana-grizzlython-winners?utm_source=Iterable&utm_medium=email&utm_campaign=campaign_6567415#:~:text=Pet%20Legends-,Zk%20Battleships,-Little%20Bonkers
23 stars 4 forks source link

Why is this nested? #15

Closed ananas-block closed 1 year ago

ananas-block commented 1 year ago

https://github.com/Shigoto-dev19/ZK-Battleships-Solana/blob/6653dee2976ecbdcff0a48529c79a9b5dd4e7685/test/game.test.ts#L106

Your file is just 100 lines long, why nest this test?

It is a lot worse for readability and just another 100 lines

Shigoto-dev19 commented 1 year ago

do you suggest breaking down the function simulate inside the test?

ananas-block commented 1 year ago

I would just do it like this it is not very long

it('Prove hit/ miss for 32 turns', async () => {
        for (let i = 1; i <= 16; i++) {
            printLog(`Bob reporting result of Alice shot #${player1_nonce - 1} (Turn ${player1_nonce * 2 - 1})`)
        /// BOB PROVES ALICE PREVIOUS REGISTERED SHOT HIT ///
        // bob's shot hit/miss integrity proof public / private inputs
        let bob_turn = await joiner.turnData(
            1,                                 // gameID 
            1,                                 // _hit                         
            shots.player2[player1_nonce - 1],  // next shot from bob to alice
            shots.player1[player1_nonce - 1]   // alice shot to verify
        ); 
        // prove alice's registered shot hit, and register bob's next shot
        await game.turn(bob_turn);

        /// ALICE PROVES BOB PREV REGISTERED SHOT MISSED ///
        printLog(`Alice reporting result of Bob shot #${player1_nonce - 1} (Turn ${player1_nonce * 2})`)
        // bob's shot hit/miss integrity proof public / private inputs
        let alice_turn = await host.turnData(
            1,                                  // gameID
            0,                                  // _hit
            shots.player1[player1_nonce],       // next shot from alice to bob
            shots.player2[player1_nonce - 1]    // bob shot to verify
        );

        // prove bob's registered shot missed, and register alice's next shot
        await game.turn(alice_turn);
        }

    })
Shigoto-dev19 commented 1 year ago

just open up the function to the test case, it is just used once so it makes sense

ananas-block commented 1 year ago

I know, I still don't like it

ananas-block commented 1 year ago

for me it makes the test a lot more difficult to read