github.com/gagliardetto/solana-go@v1.11.0/programs/system/accounts_test.go (about)

     1  // Copyright 2021 github.com/gagliardetto
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package system
    16  
    17  import (
    18  	"encoding/base64"
    19  	"testing"
    20  
    21  	bin "github.com/gagliardetto/binary"
    22  	"github.com/gagliardetto/solana-go"
    23  	"github.com/stretchr/testify/assert"
    24  )
    25  
    26  func TestDecode(t *testing.T) {
    27  	nonceAccountBase64Data := "AAAAAAEAAABHaauXIEuoP7DK7hf3ho8eB05SFYGg2J2UN52qZbcXsnM+zs3rCNyHGAjze1Gvfq4gRzzrz7ggv4rYXkMo8P2DiBMAAAAAAAA="
    28  
    29  	decoded, err := base64.StdEncoding.DecodeString(nonceAccountBase64Data)
    30  	assert.NoError(t, err)
    31  
    32  	dec := bin.NewBinDecoder(decoded)
    33  
    34  	acc := new(NonceAccount)
    35  
    36  	err = acc.UnmarshalWithDecoder(dec)
    37  	assert.NoError(t, err)
    38  
    39  	assert.Equal(t, uint32(0), acc.Version)
    40  	assert.Equal(t, uint32(1), acc.State)
    41  	assert.Equal(t, solana.MustPublicKeyFromBase58("5omQJtDUHA3gMFdHEQg1zZSvcBUVzey5WaKWYRmqF1Vj"), acc.AuthorizedPubkey)
    42  	assert.Equal(t, solana.MustPublicKeyFromBase58("8ksS6xXd7vzNrpZfBTf9gJ87Bma5AjnQ9baEcT7xH5QE"), acc.Nonce)
    43  	assert.Equal(t, uint64(5000), acc.FeeCalculator.LamportsPerSignature)
    44  }