aboutsummaryrefslogtreecommitdiff
path: root/tests.js
diff options
context:
space:
mode:
authorIan Coleman <coleman.ian@gmail.com>2017-08-02 17:02:43 +1000
committerIan Coleman <coleman.ian@gmail.com>2017-08-02 17:28:39 +1000
commit6c08f364b30e711feac698546041388325a11834 (patch)
tree0625dc7834d8ae290e6dd6bb735f5d820c7b5367 /tests.js
parentfa2e4e936eea702d9e3ea56b256bbd886ca26bdf (diff)
downloadBIP39-6c08f364b30e711feac698546041388325a11834.tar.gz
BIP39-6c08f364b30e711feac698546041388325a11834.tar.zst
BIP39-6c08f364b30e711feac698546041388325a11834.zip
Add BIP49 tab
Diffstat (limited to 'tests.js')
-rw-r--r--tests.js274
1 files changed, 274 insertions, 0 deletions
diff --git a/tests.js b/tests.js
index ea29043..b6713b0 100644
--- a/tests.js
+++ b/tests.js
@@ -3726,6 +3726,280 @@ page.open(url, function(status) {
3726}); 3726});
3727}, 3727},
3728 3728
3729// BIP49 official test vectors
3730// https://github.com/bitcoin/bips/blob/master/bip-0049.mediawiki#test-vectors
3731function() {
3732page.open(url, function(status) {
3733 // set the phrase and select bitcoin testnet
3734 var expected = "2Mww8dCYPUpKHofjgcXcBCEGmniw9CoaiD2";
3735 page.evaluate(function() {
3736 $("#bip49-tab a").click();
3737 $(".phrase").val("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about");
3738 $(".network option[selected]").removeAttr("selected");
3739 $(".network option").filter(function() {
3740 return $(this).html() == "BTC - Bitcoin Testnet";
3741 }).prop("selected", true);
3742 $(".network").trigger("change");
3743 $(".phrase").trigger("input");
3744 });
3745 // check the first address
3746 waitForGenerate(function() {
3747 var actual = page.evaluate(function() {
3748 return $(".address:first").text();
3749 });
3750 if (actual != expected) {
3751 console.log("BIP49 address is incorrect");
3752 console.log("Expected: " + expected);
3753 console.log("Actual: " + actual);
3754 fail();
3755 }
3756 next();
3757 });
3758});
3759},
3760
3761// BIP49 derivation path is shown
3762function() {
3763page.open(url, function(status) {
3764 // set the phrase
3765 var expected = "m/49'/0'/0'/0";
3766 page.evaluate(function() {
3767 $("#bip49-tab a").click();
3768 $(".phrase").val("abandon abandon ability").trigger("input");
3769 });
3770 // check the derivation path of the first address
3771 waitForGenerate(function() {
3772 var actual = page.evaluate(function() {
3773 return $("#bip49 .path").val();
3774 });
3775 if (actual != expected) {
3776 console.log("BIP49 derivation path is incorrect");
3777 console.log("Expected: " + expected);
3778 console.log("Actual: " + actual);
3779 fail();
3780 }
3781 next();
3782 });
3783});
3784},
3785
3786// BIP49 extended private key is shown
3787function() {
3788page.open(url, function(status) {
3789 // set the phrase
3790 var expected = "xprvA1hukYsW7QfX9CVsaDAKde4eryajKa4DKWb6m9YjSnqkiZHrahFwwTJfEQTwBQ5kptWT5pZMkkusT1oK8dc1efQ8VFfq4SLSPAWd7Cpt423";
3791 page.evaluate(function() {
3792 $("#bip49-tab a").click();
3793 $(".phrase").val("abandon abandon ability").trigger("input");
3794 });
3795 // check the BIP49 extended private key
3796 waitForGenerate(function() {
3797 var actual = page.evaluate(function() {
3798 return $(".extended-priv-key").val();
3799 });
3800 if (actual != expected) {
3801 console.log("BIP49 extended private key is incorrect");
3802 console.log("Expected: " + expected);
3803 console.log("Actual: " + actual);
3804 fail();
3805 }
3806 next();
3807 });
3808});
3809},
3810
3811// BIP49 extended public key is shown
3812function() {
3813page.open(url, function(status) {
3814 // set the phrase
3815 var expected = "xpub6EhGA4QPwnDpMgaLgEhKzn1PR1RDj2n4gjWhZXxM18NjbMd18EaCVFd95gkLARJaBD2rXAYJED2gdkUbGn1KkrSzCKR554AdABUELoainnt";
3816 page.evaluate(function() {
3817 $("#bip49-tab a").click();
3818 $(".phrase").val("abandon abandon ability").trigger("input");
3819 });
3820 // check the BIP49 extended public key
3821 waitForGenerate(function() {
3822 var actual = page.evaluate(function() {
3823 return $(".extended-pub-key").val();
3824 });
3825 if (actual != expected) {
3826 console.log("BIP49 extended public key is incorrect");
3827 console.log("Expected: " + expected);
3828 console.log("Actual: " + actual);
3829 fail();
3830 }
3831 next();
3832 });
3833});
3834},
3835
3836// BIP49 account field changes address list
3837function() {
3838page.open(url, function(status) {
3839 // set the phrase
3840 var expected = "381wg1GGN4rP88rNC9v7QWsiww63yLVPsn";
3841 page.evaluate(function() {
3842 $("#bip49-tab a").click();
3843 $(".phrase").val("abandon abandon ability").trigger("input");
3844 });
3845 waitForGenerate(function() {
3846 // change the bip49 account field to 1
3847 page.evaluate(function() {
3848 $("#bip49 .account").val("1");
3849 $("#bip49 .account").trigger("input");
3850 });
3851 waitForGenerate(function() {
3852 // check the address for the new derivation path
3853 var actual = page.evaluate(function() {
3854 return $(".address:first").text();
3855 });
3856 if (actual != expected) {
3857 console.log("BIP49 account field generates incorrect address");
3858 console.log("Expected: " + expected);
3859 console.log("Actual: " + actual);
3860 fail();
3861 }
3862 next();
3863 });
3864 });
3865});
3866},
3867
3868// BIP49 change field changes address list
3869function() {
3870page.open(url, function(status) {
3871 // set the phrase
3872 var expected = "3PEM7MiKed5konBoN66PQhK8r3hjGhy9dT";
3873 page.evaluate(function() {
3874 $("#bip49-tab a").click();
3875 $(".phrase").val("abandon abandon ability").trigger("input");
3876 });
3877 waitForGenerate(function() {
3878 // change the bip49 change field to 1
3879 page.evaluate(function() {
3880 $("#bip49 .change").val("1");
3881 $("#bip49 .change").trigger("input");
3882 });
3883 waitForGenerate(function() {
3884 // check the address for the new derivation path
3885 var actual = page.evaluate(function() {
3886 return $(".address:first").text();
3887 });
3888 if (actual != expected) {
3889 console.log("BIP49 change field generates incorrect address");
3890 console.log("Expected: " + expected);
3891 console.log("Actual: " + actual);
3892 fail();
3893 }
3894 next();
3895 });
3896 });
3897});
3898},
3899
3900// BIP49 account extendend private key is shown
3901function() {
3902page.open(url, function(status) {
3903 // set the phrase
3904 var expected = "xprv9y3uhgQbfQZbj3o98nfgLDwGGuCJjUn7GKArSAZXjKgMjSdYHjQmTyf78s22g6jsGrxXvHB6HJeFyvFSPkuYZajeTGMZVXV6aNLWw2fagCn";
3905 page.evaluate(function() {
3906 $("#bip49-tab a").click();
3907 $(".phrase").val("abandon abandon ability");
3908 $(".phrase").trigger("input");
3909 });
3910 // check the BIP49 account extended private key
3911 waitForGenerate(function() {
3912 var actual = page.evaluate(function() {
3913 return $("#bip49 .account-xprv").val();
3914 });
3915 if (actual != expected) {
3916 console.log("BIP49 account extended private key is incorrect");
3917 console.log("Expected: " + expected);
3918 console.log("Actual: " + actual);
3919 fail();
3920 }
3921 next();
3922 });
3923});
3924},
3925
3926// BIP49 account extendend public key is shown
3927function() {
3928page.open(url, function(status) {
3929 // set the phrase
3930 var expected = "xpub6C3G7BwVVn7twXscEpCghMszpw2o8wVxdY6TEYy9HfDLcExgqGj21myazAiq6HSmW2F1cBiFqJa3D1cqcDpSh8pbZF5x4iqpd4PyJvd3gjB";
3931 page.evaluate(function() {
3932 $("#bip49-tab a").click();
3933 $(".phrase").val("abandon abandon ability");
3934 $(".phrase").trigger("input");
3935 });
3936 // check the BIP49 account extended public key
3937 waitForGenerate(function() {
3938 var actual = page.evaluate(function() {
3939 return $("#bip49 .account-xpub").val();
3940 });
3941 if (actual != expected) {
3942 console.log("BIP49 account extended public key is incorrect");
3943 console.log("Expected: " + expected);
3944 console.log("Actual: " + actual);
3945 fail();
3946 }
3947 next();
3948 });
3949});
3950},
3951
3952// Test selecting coin where bip49 is unavailable (eg CLAM)
3953function() {
3954page.open(url, function(status) {
3955 // set the phrase
3956 page.evaluate(function() {
3957 $("#bip49-tab a").click();
3958 $(".phrase").val("abandon abandon ability");
3959 $(".phrase").trigger("input");
3960 });
3961 waitForGenerate(function() {
3962 // select non-bip49 network, ie CLAM network
3963 page.evaluate(function() {
3964 $(".network option[selected]").removeAttr("selected");
3965 $(".network option").filter(function() {
3966 return $(this).html() == "CLAM - Clams";
3967 }).prop("selected", true);
3968 $(".network").trigger("change");
3969 });
3970 // check the BIP49 error is shown
3971 var bip49ErrorShown = page.evaluate(function() {
3972 var bip49hidden = $("#bip49 .available").hasClass("hidden");
3973 bip49hidden = bip49hidden && !($("#bip49 .unavailable").hasClass("hidden"));
3974 return bip49hidden;
3975 });
3976 if (!bip49ErrorShown) {
3977 console.log("BIP49 error not shown for non-bip49 network");
3978 fail();
3979 }
3980 // check there are no addresses shown
3981 var addressCount = page.evaluate(function() {
3982 return $(".address").length;
3983 });
3984 if (addressCount != 0) {
3985 console.log("BIP49 address count for non-bip49 network is " + addressCount);
3986 fail();
3987 }
3988 // check the derived keys are blank
3989 var areBlank = page.evaluate(function() {
3990 var prvKeyIsBlank = $(".extended-priv-key").val().length == 0;
3991 var pubKeyIsBlank = $(".extended-pub-key").val().length == 0;
3992 return prvKeyIsBlank && pubKeyIsBlank;
3993 });
3994 if (!areBlank) {
3995 console.log("BIP49 extended keys for non-bip49 network are not blank ");
3996 fail();
3997 }
3998 next();
3999 });
4000});
4001},
4002
3729// If you wish to add more tests, do so here... 4003// If you wish to add more tests, do so here...
3730 4004
3731// Here is a blank test template 4005// Here is a blank test template