github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/stellar/transform_test.go (about) 1 package stellar 2 3 import ( 4 "encoding/json" 5 "reflect" 6 "testing" 7 8 "github.com/keybase/client/go/protocol/stellar1" 9 "github.com/keybase/client/go/stellar/remote" 10 ) 11 12 type atest struct { 13 name string 14 json string 15 status stellar1.AirdropStatus 16 } 17 18 var atests = []atest{ 19 { 20 name: "unqualified new account no proofs", 21 json: `{"status":{"code":0,"name":"OK"},"already_registered":false,"qualifications":{"has_stellar_key":true,"has_enough_devices":false,"service_checks":{"keybase":{"service_username":"a1","account_created":1543864123,"is_old_enough":false,"is_used_already":false,"qualifies":false},"github":{"service_username":null,"account_created":null,"is_old_enough":false,"is_used_already":true,"qualifies":false},"hackernews":{"service_username":null,"account_created":null,"is_old_enough":false,"is_used_already":true,"qualifies":false}},"qualifies_overall":false,"is_before_registration_deadline":true},"airdrop_cfg":{"min_active_devices":3,"min_active_devices_title":"3 installed devices or paper keys","registration_deadline":1571633999,"account_creation_title":"Old enough Keybase, GitHub, or Hacker News account","account_creation_subtitle":"You can connect a GitHub or Hacker News account created before January 1, 2017 to qualify.","account_used":"Note that %s was already used to qualifiy a different account for the airdrop.","account_creation_deadlines":{"keybase":1514786400,"github":1483250400,"hackernews":1483250400}},"csrf_token":"lgHZIGY1NWZmMTZmNjZmNDMzNjAyNjZiOTVkYjZmOGZlYzE5zlxSWdXOAIPWAMDEILqynj/ovmhytFw+m8Xr3ns5UJ18X//dNSQe4gZwtDK/"}`, 22 status: stellar1.AirdropStatus{ 23 State: stellar1.AirdropUnqualified, 24 Rows: []stellar1.AirdropQualification{ 25 { 26 Title: "3 installed devices or paper keys", 27 Valid: false, 28 }, 29 { 30 Title: "Old enough Keybase, GitHub, or Hacker News account", 31 Subtitle: "You can connect a GitHub or Hacker News account created before January 1, 2017 to qualify.", 32 Valid: false, 33 }, 34 }, 35 }, 36 }, 37 { 38 name: "unqualified new account used proof", 39 json: `{"status":{"code":0,"name":"OK"},"already_registered":false,"qualifications":{"has_stellar_key":true,"has_enough_devices":false,"service_checks":{"keybase":{"service_username":"a1","account_created":1543864123,"is_old_enough":false,"is_used_already":false,"qualifies":false},"github":{"service_username":"patrickxb","account_created":1000,"is_old_enough":true,"is_used_already":true,"qualifies":false},"hackernews":{"service_username":null,"account_created":null,"is_old_enough":false,"is_used_already":true,"qualifies":false}},"qualifies_overall":false,"is_before_registration_deadline":true},"airdrop_cfg":{"min_active_devices":3,"min_active_devices_title":"3 installed devices or paper keys","registration_deadline":1571633999,"account_creation_title":"Old enough Keybase, GitHub, or Hacker News account","account_creation_subtitle":"You can connect a GitHub or Hacker News account created before January 1, 2017 to qualify.","account_used":"Note that %s was already used to qualifiy a different account for the airdrop.","account_creation_deadlines":{"keybase":1514786400,"github":1483250400,"hackernews":1483250400}},"csrf_token":"lgHZIGY1NWZmMTZmNjZmNDMzNjAyNjZiOTVkYjZmOGZlYzE5zlxSWdXOAIPWAMDEILqynj/ovmhytFw+m8Xr3ns5UJ18X//dNSQe4gZwtDK/"}`, 40 status: stellar1.AirdropStatus{ 41 State: stellar1.AirdropUnqualified, 42 Rows: []stellar1.AirdropQualification{ 43 { 44 Title: "3 installed devices or paper keys", 45 Valid: false, 46 }, 47 { 48 Title: "Old enough Keybase, GitHub, or Hacker News account", 49 Subtitle: "You can connect a GitHub or Hacker News account created before January 1, 2017 to qualify. Note that patrickxb@github was already used to qualifiy a different account for the airdrop.", 50 Valid: false, 51 }, 52 }, 53 }, 54 }, 55 { 56 name: "new account qualifying proof", 57 json: `{"status":{"code":0,"name":"OK"},"already_registered":false,"qualifications":{"has_stellar_key":true,"has_enough_devices":false,"service_checks":{"keybase":{"service_username":"a1","account_created":1543864123,"is_old_enough":false,"is_used_already":false,"qualifies":false},"github":{"service_username":"patrickxb","account_created":1000,"is_old_enough":true,"is_used_already":false,"qualifies":true},"hackernews":{"service_username":null,"account_created":null,"is_old_enough":false,"is_used_already":true,"qualifies":false}},"qualifies_overall":false,"is_before_registration_deadline":true},"airdrop_cfg":{"min_active_devices":3,"min_active_devices_title":"3 installed devices or paper keys","registration_deadline":1571633999,"account_creation_title":"Old enough Keybase, GitHub, or Hacker News account","account_creation_subtitle":"You can connect a GitHub or Hacker News account created before January 1, 2017 to qualify.","account_used":"Note that %s was already used to qualifiy a different account for the airdrop.","account_creation_deadlines":{"keybase":1514786400,"github":1483250400,"hackernews":1483250400}},"csrf_token":"lgHZIGY1NWZmMTZmNjZmNDMzNjAyNjZiOTVkYjZmOGZlYzE5zlxSWdXOAIPWAMDEILqynj/ovmhytFw+m8Xr3ns5UJ18X//dNSQe4gZwtDK/"}`, 58 status: stellar1.AirdropStatus{ 59 State: stellar1.AirdropUnqualified, 60 Rows: []stellar1.AirdropQualification{ 61 { 62 Title: "3 installed devices or paper keys", 63 Valid: false, 64 }, 65 { 66 Title: "Old enough Keybase, GitHub, or Hacker News account", 67 Valid: true, 68 }, 69 }, 70 }, 71 }, 72 { 73 name: "new account qualifying proof, enough devices", 74 json: `{"status":{"code":0,"name":"OK"},"already_registered":false,"qualifications":{"has_stellar_key":true,"has_enough_devices":true,"service_checks":{"keybase":{"service_username":"a1","account_created":1543864123,"is_old_enough":false,"is_used_already":false,"qualifies":false},"github":{"service_username":"patrickxb","account_created":1000,"is_old_enough":true,"is_used_already":false,"qualifies":true},"hackernews":{"service_username":null,"account_created":null,"is_old_enough":false,"is_used_already":true,"qualifies":false}},"qualifies_overall":true,"is_before_registration_deadline":true},"airdrop_cfg":{"min_active_devices":3,"min_active_devices_title":"3 installed devices or paper keys","registration_deadline":1571633999,"account_creation_title":"Old enough Keybase, GitHub, or Hacker News account","account_creation_subtitle":"You can connect a GitHub or Hacker News account created before January 1, 2017 to qualify.","account_used":"Note that %s was already used to qualifiy a different account for the airdrop.","account_creation_deadlines":{"keybase":1514786400,"github":1483250400,"hackernews":1483250400}},"csrf_token":"lgHZIGY1NWZmMTZmNjZmNDMzNjAyNjZiOTVkYjZmOGZlYzE5zlxSWdXOAIPWAMDEILqynj/ovmhytFw+m8Xr3ns5UJ18X//dNSQe4gZwtDK/"}`, 75 status: stellar1.AirdropStatus{ 76 State: stellar1.AirdropQualified, 77 Rows: []stellar1.AirdropQualification{ 78 { 79 Title: "3 installed devices or paper keys", 80 Valid: true, 81 }, 82 { 83 Title: "Old enough Keybase, GitHub, or Hacker News account", 84 Valid: true, 85 }, 86 }, 87 }, 88 }, 89 } 90 91 func TestTransformToAirdropStatus(t *testing.T) { 92 for _, test := range atests { 93 var api remote.AirdropStatusAPI 94 if err := json.Unmarshal([]byte(test.json), &api); err != nil { 95 t.Errorf("%s: error: %s", test.name, err) 96 continue 97 } 98 out := TransformToAirdropStatus(api) 99 if !reflect.DeepEqual(out, test.status) { 100 t.Errorf("%s: transform output didn't match, expected %+v, got %+v", test.name, test.status, out) 101 } 102 } 103 }