From 4c71f5ee3c65de608df642abd1d59557b092c6c8 Mon Sep 17 00:00:00 2001 From: georgehao Date: Fri, 12 Apr 2024 00:58:11 +0800 Subject: [PATCH] feat: fix unit test --- coordinator/test/mock_prover.go | 35 ++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/coordinator/test/mock_prover.go b/coordinator/test/mock_prover.go index dfad28b9b0..67ce32b3a6 100644 --- a/coordinator/test/mock_prover.go +++ b/coordinator/test/mock_prover.go @@ -77,18 +77,31 @@ func (r *mockProver) challenge(t *testing.T) string { } func (r *mockProver) login(t *testing.T, challengeString string, forkName string) string { - authMsg := message.AuthMsg{ - Identity: &message.Identity{ - Challenge: challengeString, - ProverName: r.proverName, - ProverVersion: r.proverVersion, - HardForkName: forkName, - }, + var body string + if forkName != "" { + authMsg := message.AuthMsg{ + Identity: &message.Identity{ + Challenge: challengeString, + ProverName: r.proverName, + ProverVersion: r.proverVersion, + HardForkName: forkName, + }, + } + assert.NoError(t, authMsg.SignWithKey(r.privKey)) + body = fmt.Sprintf("{\"message\":{\"challenge\":\"%s\",\"prover_name\":\"%s\", \"prover_version\":\"%s\", \"hard_fork_name\":\"%s\"},\"signature\":\"%s\"}", + authMsg.Identity.Challenge, authMsg.Identity.ProverName, authMsg.Identity.ProverVersion, authMsg.Identity.HardForkName, authMsg.Signature) + } else { + authMsg := message.LegacyAuthMsg{ + Identity: &message.LegacyIdentity{ + Challenge: challengeString, + ProverName: r.proverName, + ProverVersion: r.proverVersion, + }, + } + assert.NoError(t, authMsg.SignWithKey(r.privKey)) + body = fmt.Sprintf("{\"message\":{\"challenge\":\"%s\",\"prover_name\":\"%s\", \"prover_version\":\"%s\"},\"signature\":\"%s\"}", + authMsg.Identity.Challenge, authMsg.Identity.ProverName, authMsg.Identity.ProverVersion, authMsg.Signature) } - assert.NoError(t, authMsg.SignWithKey(r.privKey)) - - body := fmt.Sprintf("{\"message\":{\"challenge\":\"%s\",\"prover_name\":\"%s\", \"prover_version\":\"%s\", \"hard_fork_name\":\"%s\"},\"signature\":\"%s\"}", - authMsg.Identity.Challenge, authMsg.Identity.ProverName, authMsg.Identity.ProverVersion, authMsg.Identity.HardForkName, authMsg.Signature) var result ctypes.Response client := resty.New()