(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func Test_proofPayload(t *testing.T) { |
| 14 | t.Run("success", func(t *testing.T) { |
| 15 | before_each(t) |
| 16 | req := ProofPayloadRequest{ |
| 17 | Action: "create", |
| 18 | Platform: "twitter", |
| 19 | Identity: "yeiwb", |
| 20 | PublicKey: "0x028c3cda474361179d653c41a62f6bbb07265d535121e19aedf660da2924d0b1e3", |
| 21 | } |
| 22 | resp := ProofPayloadResponse{} |
| 23 | APITestCall(Engine, "POST", "/v1/proof/payload", &req, &resp) |
| 24 | assert.Contains(t, resp.SignPayload, "\"action\":\"create\"") |
| 25 | assert.Contains(t, resp.SignPayload, "\"platform\":\"twitter\"") |
| 26 | assert.Contains(t, resp.SignPayload, "\"identity\":\"yeiwb\"") |
| 27 | assert.Contains(t, resp.SignPayload, "\"prev\":null") |
| 28 | |
| 29 | assert.Contains(t, resp.PostContent["default"], "Verifying my Twitter ID") |
| 30 | assert.Contains(t, resp.PostContent["default"], req.Identity) |
| 31 | assert.Contains(t, resp.PostContent["default"], "Sig:") |
| 32 | assert.Contains(t, resp.PostContent["default"], "%SIG_BASE64%") |
| 33 | |
| 34 | assert.True(t, len(resp.Uuid) > 0) |
| 35 | assert.True(t, len(resp.CreatedAt) > 0) |
| 36 | }) |
| 37 | |
| 38 | t.Run("with previous", func(t *testing.T) { |
| 39 | before_each(t) |
| 40 | pk, _ := crypto.StringToPubkey("0x028c3cda474361179d653c41a62f6bbb07265d535121e19aedf660da2924d0b1e3") |
| 41 | |
| 42 | proof := model.ProofChain{ |
| 43 | Persona: "0x" + crypto.CompressedPubkeyHex(pk), |
| 44 | Platform: "twitter", |
| 45 | Identity: "yeiwb", |
| 46 | Location: "1469221200140574721", |
| 47 | Signature: "gMUJ75eewkdaNrFp7bafzckv9+rlW7rVaxkB7/sYzYgFdFltYG+gn0lYzVNgrAdHWZPmu2giwJniGG7HG9iNigE=", |
| 48 | } |
| 49 | tx := model.DB.Create(&proof) |
| 50 | assert.Nil(t, tx.Error) |
| 51 | |
| 52 | req := ProofPayloadRequest{ |
| 53 | Action: "delete", |
| 54 | Platform: "twitter", |
| 55 | Identity: "yeiwb", |
| 56 | PublicKey: "0x" + crypto.CompressedPubkeyHex(pk), |
| 57 | } |
| 58 | resp := ProofPayloadResponse{} |
| 59 | |
| 60 | APITestCall(Engine, "POST", "/v1/proof/payload", &req, &resp) |
| 61 | sign_payload := gin.H{} |
| 62 | |
| 63 | assert.Nil(t, json.Unmarshal([]byte(resp.SignPayload), &sign_payload)) |
| 64 | prev, ok := sign_payload["prev"] |
| 65 | assert.True(t, ok) |
| 66 | t.Logf("Prev: %s", prev) |
| 67 | assert.Equal(t, prev, proof.Signature) |
| 68 | }) |
| 69 | |
| 70 | } |
nothing calls this directly
no test coverage detected