How to use Code method of td Package

Best Go-testdeep code snippet using td.Code

test.go

Source:test.go Github

copy

Full Screen

...62 }63 DefaultInitActorState = ActorState{64 Addr: builtin_spec.InitActorAddr,65 Balance: big_spec.Zero(),66 Code: builtin_spec.InitActorCodeID,67 State: init_spec.ConstructState(EmptyMapCid, "chain-validation"),68 }69 firstRewardState := reward_spec.ConstructState(big_spec.Zero())70 firstRewardState.ThisEpochReward = big_spec.NewInt(1e17)71 DefaultRewardActorState = ActorState{72 Addr: builtin_spec.RewardActorAddr,73 Balance: TotalNetworkBalance,74 Code: builtin_spec.RewardActorCodeID,75 State: firstRewardState,76 }77 DefaultBurntFundsActorState = ActorState{78 Addr: builtin_spec.BurntFundsActorAddr,79 Balance: big_spec.Zero(),80 Code: builtin_spec.AccountActorCodeID,81 State: &account_spec.State{Address: builtin_spec.BurntFundsActorAddr},82 }83 DefaultStoragePowerActorState = ActorState{84 Addr: builtin_spec.StoragePowerActorAddr,85 Balance: big_spec.Zero(),86 Code: builtin_spec.StoragePowerActorCodeID,87 State: power_spec.ConstructState(EmptyMapCid, EmptyMultiMapCid),88 }89 DefaultStorageMarketActorState = ActorState{90 Addr: builtin_spec.StorageMarketActorAddr,91 Balance: big_spec.Zero(),92 Code: builtin_spec.StorageMarketActorCodeID,93 State: &market_spec.State{94 Proposals: EmptyArrayCid,95 States: EmptyArrayCid,96 PendingProposals: EmptyMapCid,97 EscrowTable: EmptyMapCid,98 LockedTable: EmptyMapCid,99 NextID: abi_spec.DealID(0),100 DealOpsByEpoch: EmptyMultiMapCid,101 LastCron: 0,102 },103 }104 DefaultSystemActorState = ActorState{105 Addr: builtin_spec.SystemActorAddr,106 Balance: big_spec.Zero(),107 Code: builtin_spec.SystemActorCodeID,108 State: &system.State{},109 }110 DefaultCronActorState = ActorState{111 Addr: builtin_spec.CronActorAddr,112 Balance: big_spec.Zero(),113 Code: builtin_spec.CronActorCodeID,114 State: &cron_spec.State{Entries: []cron_spec.Entry{115 {116 Receiver: builtin_spec.StoragePowerActorAddr,117 MethodNum: builtin_spec.MethodsPower.OnEpochTickEnd,118 },119 }},120 }121 DefaultBuiltinActorsState = []ActorState{122 DefaultInitActorState,123 DefaultRewardActorState,124 DefaultBurntFundsActorState,125 DefaultStoragePowerActorState,126 DefaultStorageMarketActorState,127 DefaultSystemActorState,128 DefaultCronActorState,129 }130}131func initializeStoreWithAdtRoots(store adt_spec.Store) error {132 var err error133 EmptyArrayCid, err = adt_spec.MakeEmptyArray(store).Root()134 if err != nil {135 return err136 }137 EmptyMapCid, err = adt_spec.MakeEmptyMap(store).Root()138 if err != nil {139 return err140 }141 EmptyMultiMapCid, err = adt_spec.MakeEmptyMultimap(store).Root()142 if err != nil {143 return err144 }145 EmptyDeadlinesCid, err = store.Put(context.TODO(), miner.ConstructDeadline(EmptyArrayCid))146 if err != nil {147 return err148 }149 EmptyVestingFundsCid, err = store.Put(context.Background(), miner.ConstructVestingFunds())150 if err != nil {151 return err152 }153 EmptyBitfieldCid, err = store.Put(context.TODO(), bitfield.New())154 if err != nil {155 return err156 }157 return nil158}159type mockStore struct {160 ctx context.Context161 cbor.IpldStore162}163func newMockStore() *mockStore {164 bs := blockstore.NewBlockstore(datastore.NewMapDatastore())165 cst := cbor.NewCborStore(bs)166 return &mockStore{167 ctx: context.Background(),168 IpldStore: cst,169 }170}171func (m mockStore) Context() context.Context {172 return m.ctx173}174type TestDriverBuilder struct {175 ctx context.Context176 factory state.Factories177 actorStates []ActorState178 defaultGasFeeCap abi_spec.TokenAmount179 defaultGasPremium abi_spec.TokenAmount180 defaultGasLimit int64181}182func NewBuilder(ctx context.Context, factory state.Factories) *TestDriverBuilder {183 return &TestDriverBuilder{184 factory: factory,185 ctx: ctx,186 }187}188type ActorState struct {189 Addr address.Address190 Balance abi_spec.TokenAmount191 Code cid.Cid192 State runtime_spec.CBORMarshaler193}194func (b *TestDriverBuilder) WithActorState(acts ...ActorState) *TestDriverBuilder {195 b.actorStates = append(b.actorStates, acts...)196 return b197}198func (b *TestDriverBuilder) WithDefaultGasLimit(limit int64) *TestDriverBuilder {199 b.defaultGasLimit = limit200 return b201}202func (b *TestDriverBuilder) WithDefaultGasFeeCap(feeCap int64) *TestDriverBuilder {203 b.defaultGasFeeCap = abi_spec.NewTokenAmount(feeCap)204 return b205}206func (b *TestDriverBuilder) WithDefaultGasPremium(premium int64) *TestDriverBuilder {207 b.defaultGasPremium = abi_spec.NewTokenAmount(premium)208 return b209}210func (b *TestDriverBuilder) Build(t testing.TB) *TestDriver {211 syscalls := NewChainValidationSysCalls()212 stateWrapper, applier := b.factory.NewStateAndApplier(syscalls)213 sd := NewStateDriver(t, stateWrapper, b.factory.NewKeyManager())214 stateWrapper.NewVM()215 err := initializeStoreWithAdtRoots(AsStore(sd.st))216 require.NoError(t, err)217 for _, acts := range b.actorStates {218 _, _, err := sd.State().CreateActor(acts.Code, acts.Addr, acts.Balance, acts.State)219 require.NoError(t, err)220 }221 minerActorIDAddr := sd.newMinerAccountActor(TestSealProofType, abi_spec.ChainEpoch(0))222 exeCtx := types.NewExecutionContext(1, minerActorIDAddr)223 producer := chain.NewMessageProducer(b.defaultGasFeeCap, b.defaultGasPremium, b.defaultGasLimit)224 validator := chain.NewValidator(applier)225 return &TestDriver{226 T: t,227 StateDriver: sd,228 MessageProducer: producer,229 validator: validator,230 ExeCtx: exeCtx,231 Config: b.factory.NewValidationConfig(),232 StateTracker: tracker.NewStateTracker(t),233 SysCalls: syscalls,234 }235}236type TestDriver struct {237 *StateDriver238 T testing.TB239 MessageProducer *chain.MessageProducer240 TipSetMessageBuilder *TipSetMessageBuilder241 validator *chain.Validator242 ExeCtx *types.ExecutionContext243 Config state.ValidationConfig244 StateTracker *tracker.StateTracker245 SysCalls *ChainValidationSysCalls246}247func (td *TestDriver) Complete() {248 //249 // Gas expectation recording.250 // Uncomment the following line to persist the actual gas values used to file as the new set251 // of expectations.252 //td.StateTracker.Record()253}254//255// Unsigned Message Appliers256//257func (td *TestDriver) ApplyMessage(msg *types.Message) types.ApplyMessageResult {258 result := td.applyMessage(msg)259 td.validateState(msg, result)260 return result261}262func (td *TestDriver) ApplyOk(msg *types.Message) types.ApplyMessageResult {263 return td.ApplyExpect(msg, EmptyReturnValue)264}265func (td *TestDriver) ApplyExpect(msg *types.Message, retval []byte) types.ApplyMessageResult {266 return td.applyMessageExpectCodeAndReturn(msg, exitcode.Ok, retval)267}268func (td *TestDriver) ApplyFailure(msg *types.Message, code exitcode.ExitCode) types.ApplyMessageResult {269 return td.applyMessageExpectCodeAndReturn(msg, code, EmptyReturnValue)270}271func (td *TestDriver) applyMessageExpectCodeAndReturn(msg *types.Message, code exitcode.ExitCode, retval []byte) types.ApplyMessageResult {272 result := td.applyMessage(msg)273 td.validateResult(result, code, retval)274 td.validateState(msg, result)275 return result276}277func (td *TestDriver) applyMessage(msg *types.Message) (result types.ApplyMessageResult) {278 defer func() {279 if r := recover(); r != nil {280 td.T.Fatalf("message application panicked: %v", r)281 }282 }()283 result, err := td.validator.ApplyMessage(td.ExeCtx.Epoch, msg)284 require.NoError(td.T, err)285 td.StateTracker.TrackResult(result)286 return result287}288//289// Signed Message Appliers290//291func (td *TestDriver) ApplySigned(msg *types.Message) types.ApplyMessageResult {292 result := td.applyMessageSigned(msg)293 td.validateState(msg, result)294 return result295}296func (td *TestDriver) ApplySignedOk(msg *types.Message) types.ApplyMessageResult {297 return td.ApplySignedExpect(msg, EmptyReturnValue)298}299func (td *TestDriver) ApplySignedExpect(msg *types.Message, retval []byte) types.ApplyMessageResult {300 return td.applyMessageSignedExpectCodeAndReturn(msg, exitcode.Ok, retval)301}302func (td *TestDriver) ApplySignedFailure(msg *types.Message, code exitcode.ExitCode) types.ApplyMessageResult {303 return td.applyMessageExpectCodeAndReturn(msg, code, EmptyReturnValue)304}305func (td *TestDriver) applyMessageSignedExpectCodeAndReturn(msg *types.Message, code exitcode.ExitCode, retval []byte) types.ApplyMessageResult {306 result := td.applyMessageSigned(msg)307 td.validateResult(result, code, retval)308 td.validateState(msg, result)309 return result310}311func (td *TestDriver) applyMessageSigned(msg *types.Message) (result types.ApplyMessageResult) {312 defer func() {313 if r := recover(); r != nil {314 td.T.Fatalf("message application panicked: %v", r)315 }316 }()317 serMsg, err := msg.Serialize()318 require.NoError(td.T, err)319 msgSig, err := td.Wallet().Sign(msg.From, serMsg)320 require.NoError(td.T, err)321 smsgs := &types.SignedMessage{322 Message: *msg,323 Signature: msgSig,324 }325 result, err = td.validator.ApplySignedMessage(td.ExeCtx.Epoch, smsgs)326 require.NoError(td.T, err)327 td.StateTracker.TrackResult(result)328 return result329}330func (td *TestDriver) validateResult(result types.ApplyMessageResult, code exitcode.ExitCode, retval []byte) {331 if td.Config.ValidateExitCode() {332 assert.Equal(td.T, code, result.Receipt.ExitCode, "Expected ExitCode: %s Actual ExitCode: %s", code.Error(), result.Receipt.ExitCode.Error())333 }334 if td.Config.ValidateReturnValue() {335 assert.Equal(td.T, retval, result.Receipt.ReturnValue, "Expected ReturnValue: %v Actual ReturnValue: %v", retval, result.Receipt.ReturnValue)336 }337}338func (td *TestDriver) validateState(msg *types.Message, result types.ApplyMessageResult) {339 if td.Config.ValidateGas() {340 expectedGasUsed, ok := td.StateTracker.NextExpectedGas()341 if ok {342 assert.Equal(td.T, expectedGasUsed, result.Receipt.GasUsed, "Expected GasUsed: %d Actual GasUsed: %d", expectedGasUsed, result.Receipt.GasUsed)343 } else {344 td.T.Logf("WARNING (not a test failure): failed to find expected gas cost for message: %+v", msg)345 }346 }347 if td.Config.ValidateStateRoot() {348 expectedRoot, found := td.StateTracker.NextExpectedStateRoot()349 actualRoot := td.State().Root()350 if found {351 assert.Equal(td.T, expectedRoot, actualRoot, "Expected StateRoot: %s Actual StateRoot: %s", expectedRoot, actualRoot)352 } else {353 td.T.Log("WARNING: failed to find expected state root for message number")354 }355 }356}357func (td *TestDriver) AssertNoActor(addr address.Address) {358 _, err := td.State().Actor(addr)359 assert.Error(td.T, err, "expected no such actor %s", addr)360}361func (td *TestDriver) GetBalance(addr address.Address) abi_spec.TokenAmount {362 actr, err := td.State().Actor(addr)363 require.NoError(td.T, err)364 return actr.Balance()365}366func (td *TestDriver) GetHead(addr address.Address) cid.Cid {367 actr, err := td.State().Actor(addr)368 require.NoError(td.T, err)369 return actr.Head()370}371// AssertBalance checks an actor has an expected balance.372func (td *TestDriver) AssertBalance(addr address.Address, expected abi_spec.TokenAmount) {373 actr, err := td.State().Actor(addr)374 require.NoError(td.T, err)375 assert.Equal(td.T, expected, actr.Balance(), fmt.Sprintf("expected actor %s balance: %s, actual balance: %s", addr, expected, actr.Balance()))376}377// Checks that after executing a message, the sender actor's balance is as expected, given378// - the actor's previous balance379// - the gas limit of the executed message380// - the gas price of the executed message381// - the value transferred by the executed message382func (td *TestDriver) AssertActorChange(addr address.Address, prevBalance abi_spec.TokenAmount, gasLimit int64, gasPrice big_spec.Int, transferred big_spec.Int, rct types.MessageReceipt, callSeqNum uint64) {383 actr, err := td.State().Actor(addr)384 require.NoError(td.T, err)385 expected := big_spec.Sub(prevBalance, td.CalcMessageCost(gasLimit, gasPrice, transferred, rct))386 assert.Equal(td.T, expected.String(), actr.Balance().String(), fmt.Sprintf("expected actor %s balance: %s, actual balance: %s", addr, expected, actr.Balance()))387 assert.Equal(td.T, callSeqNum, actr.CallSeqNum(), fmt.Sprintf("expected actor %s callSeqNum: %d, actual : %d", addr, callSeqNum, actr.CallSeqNum()))388}389func (td *TestDriver) AssertHead(addr address.Address, expected cid.Cid) {390 head := td.GetHead(addr)391 assert.Equal(td.T, expected, head, "expected actor %s head %s, actual %s", addr, expected, head)392}393func (td *TestDriver) AssertBalanceCallback(addr address.Address, thing func(actorBalance abi_spec.TokenAmount) bool) {394 actr, err := td.State().Actor(addr)395 require.NoError(td.T, err)396 assert.True(td.T, thing(actr.Balance()))397}398func (td *TestDriver) AssertMultisigTransaction(multisigAddr address.Address, txnID multisig_spec.TxnID, txn multisig_spec.Transaction) {399 var msState multisig_spec.State400 td.GetActorState(multisigAddr, &msState)401 txnMap, err := adt_spec.AsMap(AsStore(td.State()), msState.PendingTxns)402 require.NoError(td.T, err)403 var actualTxn multisig_spec.Transaction404 found, err := txnMap.Get(txnID, &actualTxn)405 require.NoError(td.T, err)406 require.True(td.T, found)407 assert.Equal(td.T, txn, actualTxn)408}409func (td *TestDriver) AssertMultisigContainsTransaction(multisigAddr address.Address, txnID multisig_spec.TxnID, contains bool) {410 var msState multisig_spec.State411 td.GetActorState(multisigAddr, &msState)412 txnMap, err := adt_spec.AsMap(AsStore(td.State()), msState.PendingTxns)413 require.NoError(td.T, err)414 var actualTxn multisig_spec.Transaction415 found, err := txnMap.Get(txnID, &actualTxn)416 require.NoError(td.T, err)417 assert.Equal(td.T, contains, found)418}419func (td *TestDriver) AssertMultisigState(multisigAddr address.Address, expected multisig_spec.State) {420 var msState multisig_spec.State421 td.GetActorState(multisigAddr, &msState)422 assert.NotNil(td.T, msState)423 assert.Equal(td.T, expected.InitialBalance, msState.InitialBalance, fmt.Sprintf("expected InitialBalance: %v, actual InitialBalance: %v", expected.InitialBalance, msState.InitialBalance))424 assert.Equal(td.T, expected.NextTxnID, msState.NextTxnID, fmt.Sprintf("expected NextTxnID: %v, actual NextTxnID: %v", expected.NextTxnID, msState.NextTxnID))425 assert.Equal(td.T, expected.NumApprovalsThreshold, msState.NumApprovalsThreshold, fmt.Sprintf("expected NumApprovalsThreshold: %v, actual NumApprovalsThreshold: %v", expected.NumApprovalsThreshold, msState.NumApprovalsThreshold))426 assert.Equal(td.T, expected.StartEpoch, msState.StartEpoch, fmt.Sprintf("expected StartEpoch: %v, actual StartEpoch: %v", expected.StartEpoch, msState.StartEpoch))427 assert.Equal(td.T, expected.UnlockDuration, msState.UnlockDuration, fmt.Sprintf("expected UnlockDuration: %v, actual UnlockDuration: %v", expected.UnlockDuration, msState.UnlockDuration))428 for _, e := range expected.Signers {429 assert.Contains(td.T, msState.Signers, e, fmt.Sprintf("expected Signer: %v, actual Signer: %v", e, msState.Signers))430 }431}432func (td *TestDriver) ComputeInitActorExecReturn(from address.Address, originatorCallSeq uint64, newActorAddressCount uint64, expectedNewAddr address.Address) init_spec.ExecReturn {433 td.T.Helper()434 return computeInitActorExecReturn(td.T, from, originatorCallSeq, newActorAddressCount, expectedNewAddr)435}436func computeInitActorExecReturn(t testing.TB, from address.Address, originatorCallSeq uint64, newActorAddressCount uint64, expectedNewAddr address.Address) init_spec.ExecReturn {437 t.Helper()438 buf := new(bytes.Buffer)439 if from.Protocol() == address.ID {440 t.Fatal("cannot compute init actor address return from ID address", from)441 }442 require.NoError(t, from.MarshalCBOR(buf))443 require.NoError(t, binary.Write(buf, binary.BigEndian, originatorCallSeq))444 require.NoError(t, binary.Write(buf, binary.BigEndian, newActorAddressCount))445 out, err := address.NewActorAddress(buf.Bytes())446 require.NoError(t, err)447 return init_spec.ExecReturn{448 IDAddress: expectedNewAddr,449 RobustAddress: out,450 }451}452func (td *TestDriver) MustCreateAndVerifyMultisigActor(nonce uint64, value abi_spec.TokenAmount, multisigAddr address.Address, from address.Address, params *multisig_spec.ConstructorParams, code exitcode.ExitCode, retval []byte) {453 /* Create the Multisig actor*/454 td.applyMessageExpectCodeAndReturn(455 td.MessageProducer.CreateMultisigActor(from, params.Signers, params.UnlockDuration, params.NumApprovalsThreshold, chain.Nonce(nonce), chain.Value(value)),456 code, retval)457 /* Assert the actor state was setup as expected */458 pendingTxMapRoot, err := adt_spec.MakeEmptyMap(newMockStore()).Root()459 require.NoError(td.T, err)460 initialBalance := big_spec.Zero()461 startEpoch := abi_spec.ChainEpoch(0)462 if params.UnlockDuration > 0 {463 initialBalance = value464 startEpoch = td.ExeCtx.Epoch465 }466 td.AssertMultisigState(multisigAddr, multisig_spec.State{467 NextTxnID: 0,468 InitialBalance: initialBalance,...

Full Screen

Full Screen

templates.go

Source:templates.go Github

copy

Full Screen

1package http2var index = `3<!DOCTYPE html>4<html lang="en">5 <head>6 <meta charset="utf-8">7 <meta http-equiv="X-UA-Compatible" content="IE=edge">8 <meta name="viewport" content="width=device-width, initial-scale=1">9 <title>nintengo - {{.NES.GameName}}</title>10 <!-- Latest compiled and minified CSS -->11 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">12 <!-- Optional theme -->13 <link href="//maxcdn.bootstrapcdn.com/bootswatch/3.2.0/darkly/bootstrap.min.css" rel="stylesheet">14 <!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css"> -->15 <style>16 body { padding-top: 70px; }17 </style>18 </head>19 <body>20 <div class='container'>21 <div class='row'>22 <nav class="navbar navbar-default navbar-fixed-top" role="navigation">23 <div class="container-fluid">24 <!-- Brand and toggle get grouped for better mobile display -->25 <div class="navbar-header">26 <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">27 <span class="sr-only">Toggle navigation</span>28 <span class="icon-bar"></span>29 <span class="icon-bar"></span>30 <span class="icon-bar"></span>31 </button>32 <a class="navbar-brand" href="#">nintengo</a>33 </div>34 <!-- Collect the nav links, forms, and other content for toggling -->35 <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">36 <ul class="nav navbar-nav">37 <li class='active'><a href='#'>{{.NES.GameName}}</a></li>38 <li><a href='#' id='pause-link'>Pause</a></li>39 <li><a href='#' id='save-state-link'>Save State</a></li>40 <li><a href='#' id='load-state-link'>Load State</a></li>41 <li><a href='#' id='reset-link'>Reset</a></li>42 </ul>43 <ul class="nav navbar-nav navbar-right">44 <li><a href='#' id='run-state'></a></li>45 <li><a href='#' id='step-state'></a></li>46 </ul>47 </div><!-- /.navbar-collapse -->48 </div><!-- /.container-fluid -->49 </nav>50 <div class='col-md-6'>51 <table class='table table-striped'>52 <thead><tr><td><strong>CPU Variable</strong></td><td><strong>Value</strong></td></tr></thead>53 <tbody>54 <tr><td><kbd>A</kbd></td> <td><code>{{printf "$%02x" .NES.CPU.M6502.Registers.A}}</code></td></tr>55 <tr><td><kbd>X</kbd></td> <td><code>{{printf "$%02x" .NES.CPU.M6502.Registers.X}}</code></td></tr>56 <tr><td><kbd>Y</kbd></td> <td><code>{{printf "$%02x" .NES.CPU.M6502.Registers.Y}}</code></td></tr>57 <tr><td><kbd>P</kbd></td> <td><code>{{printf "$%02x" .NES.CPU.M6502.Registers.P}}</code></td></tr>58 <tr><td><kbd>SP</kbd></td> <td><code>{{printf "$%04x" .NES.CPU.M6502.Registers.SP}}</code></td></tr>59 <tr><td><kbd>PC</kbd></td> <td><code>{{printf "$%04x" .NES.CPU.M6502.Registers.PC}}</code></td></tr>60 <tr><td><kbd>NMI</kbd></td> <td><code>{{.NES.CPU.M6502.Nmi}}</code></td> </tr>61 <tr><td><kbd>IRQ</kbd></td> <td><code>{{.NES.CPU.M6502.Irq}}</code></td> </tr>62 <tr><td><kbd>RST</kbd></td> <td><code>{{.NES.CPU.M6502.Rst}}</code></td> </tr>63 </tbody>64 <thead><tr><td><strong>DMA Variable</strong></td><td><strong>Value</strong></td></tr></thead>65 <tbody>66 <tr><td><kbd>Pending</kbd></td> <td><code>{{printf "$%04x" .NES.CPU.DMA.Pending}}</code></td> </tr>67 </tbody>68 <thead><tr><td><strong>APU Variable</strong></td><td><strong>Value</strong></td></tr></thead>69 <tbody>70 <tr><td><kbd>Control</kbd></td> <td><code>{{printf "$%02x" .NES.CPU.APU.Registers.Control}}</code></td></tr>71 <tr><td><kbd>Status</kbd></td> <td><code>{{printf "$%02x" .NES.CPU.APU.Registers.Status}}</code></td></tr>72 </tbody>73 <thead><tr><td><strong>PPU Variable</strong></td><td><strong>Value</strong></td></tr></thead>74 <tbody>75 <tr><td><kbd>Frame</kbd></td> <td><code>{{.NES.PPU.Frame}}</code></td></tr>76 <tr><td><kbd>Scanline</kbd></td> <td><code>{{.NES.PPU.Scanline}}</code></td></tr>77 <tr><td><kbd>Cycle</kbd></td> <td><code>{{.NES.PPU.Cycle}}</code></td></tr>78 <tr><td><kbd>Controller</kbd></td> <td><code>{{printf "$%02x" .NES.PPU.Registers.Controller}}</code></td></tr>79 <tr><td><kbd>Mask</kbd></td> <td><code>{{printf "$%02x" .NES.PPU.Registers.Mask}}</code></td></tr>80 <tr><td><kbd>Status</kbd></td> <td><code>{{printf "$%02x" .NES.PPU.Registers.Status}}</code></td></tr>81 <tr><td><kbd>OAMAddress</kbd></td> <td><code>{{printf "$%02x" .NES.PPU.Registers.OAMAddress}}</code></td></tr>82 <tr><td><kbd>Scroll</kbd></td> <td><code>{{printf "$%04x" .NES.PPU.Registers.Scroll}}</code></td></tr>83 <tr><td><kbd>Address</kbd></td> <td><code>{{printf "$%04x" .NES.PPU.Registers.Address}}</code></td></tr>84 <tr><td><kbd>Data</kbd></td> <td><code>{{printf "$%02x" .NES.PPU.Registers.Data}}</code></td></tr>85 <tr><td><kbd>Latch</kbd></td> <td><code>{{.NES.PPU.Latch}}</code></td></tr>86 <tr><td><kbd>LatchAddress</kbd></td> <td><code>{{printf "$%04x" .NES.PPU.LatchAddress}}</code></td></tr>87 <tr><td><kbd>LatchValue</kbd></td> <td><code>{{printf "$%02x" .NES.PPU.LatchValue}}</code></td></tr>88 <tr><td><kbd>AddressLine</kbd></td> <td><code>{{printf "$%04x" .NES.PPU.AddressLine}}</code></td></tr>89 <tr><td><kbd>PatternAddress</kbd></td> <td><code>{{printf "$%04x" .NES.PPU.PatternAddress}}</code></td></tr>90 <tr><td><kbd>AttributeNext</kbd></td> <td><code>{{printf "$%02x" .NES.PPU.AttributeNext}}</code></td></tr>91 <tr><td><kbd>AttributeLatch</kbd></td> <td><code>{{printf "$%02x" .NES.PPU.AttributeLatch}}</code></td></tr>92 <tr><td><kbd>Attributes</kbd></td> <td><code>{{printf "$%04x" .NES.PPU.Attributes}}</code></td></tr>93 <tr><td><kbd>TilesLow</kbd></td> <td><code>{{printf "$%02x" .NES.PPU.TilesLow}}</code></td></tr>94 <tr><td><kbd>TilesHigh</kbd></td> <td><code>{{printf "$%02x" .NES.PPU.TilesHigh}}</code></td></tr>95 <tr><td><kbd>TilesLatchLow</kbd></td> <td><code>{{printf "$%02x" .NES.PPU.TilesLatchLow}}</code></td></tr>96 <tr><td><kbd>TilesLatchHigh</kbd></td> <td><code>{{printf "$%02x" .NES.PPU.TilesLatchHigh}}</code></td></tr>97 <thead><tr><td><strong>OAM Variable</strong></td><td><strong>Value</strong></td></tr></thead>98 <tbody>99 <tr><td><kbd>Address</kbd></td> <td><code>{{printf "$%04x" .NES.PPU.OAM.Address}}</code></td></tr>100 <tr><td><kbd>Latch</kbd></td> <td><code>{{printf "$%02x" .NES.PPU.OAM.Latch}}</code></td></tr>101 <tr><td><kbd>SpriteZeroInBuffer</kbd></td> <td><code>{{.NES.PPU.OAM.SpriteZeroInBuffer}}</code></td></tr>102 </tbody>103 </table>104 <h4>CPU Memory</h4>105 <pre style='font-size: 11px' class='pre-scrollable'>{{.CPUMemory}}</pre>106 <h4>PPU Memory</h4>107 <pre style='font-size: 11px' class='pre-scrollable'>{{.PPUMemory}}</pre>108 <h4>PPU Palette</h4>109 <pre style='font-size: 11px' class='pre-scrollable'>{{.PPUPalette}}</pre>110 <h4>OAM Memory</h4>111 <pre style='font-size: 11px' class='pre-scrollable'>{{.OAMMemory}}</pre>112 <h4>OAM Buffer Memory</h4>113 <pre style='font-size: 11px' class='pre-scrollable'>{{.OAMBufferMemory}}</pre>114 </div>115 <div class='col-md-6'>116 <table class='table table-striped'>117 {{range $i, $s := .NES.PPU.Sprites}}118 <thead><tr><td><strong>PPU Sprite {{$i}} Variable</strong></td><td><strong>Value</strong></td></tr></thead>119 <tbody>120 <tr><td><kbd>TileLow </kbd></td> <td><code>{{printf "$%0x2" $s.TileLow}}</code></td></tr>121 <tr><td><kbd>TileHigh </kbd></td> <td><code>{{printf "$%0x2" $s.TileHigh}}</code></td></tr>122 <tr><td><kbd>Sprite </kbd></td> <td><code>{{printf "$%08x" $s.Sprite}}</code></td></tr>123 <tr><td><kbd>XPosition </kbd></td> <td><code>{{printf "$%02x" $s.XPosition}}</code></td></tr>124 <tr><td><kbd>Address </kbd></td> <td><code>{{printf "$%04x" $s.Address}}</code></td></tr>125 <tr><td><kbd>Priority </kbd></td> <td><code>{{printf "$%02x" $s.Priority}}</code></td></tr>126 {{end}}127 </tbody>128 </table>129 </div>130 </div>131 <div class='row'>132 <div class='col-md-8'>133 <h4>PPU Pattern Tables</h4>134 </div>135 <div class='col-md-6'>136 <img alt='left' style='width:100%;' src='data:image/png;base64,{{.PTLeft}}' class='img-thumbnail img-responsive' />137 </div>138 <div class='col-md-6'>139 <img alt='right' style='width:100%;' src='data:image/png;base64,{{.PTRight}}' class='img-thumbnail img-responsive' />140 </div>141 </div>142 <div id='load-result' style='display: none'></div>143 </div>144 <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->145 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>146 <!-- Latest compiled and minified JavaScript -->147 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>148 <script>149 $('#run-state').load('/run-state');150 $('#run-state').show();151 $('#pause-link').click(function(e) {152 e.preventDefault();153 $('#run-state').load('/pause');154 location.reload();155 });156 $('#save-state-link').click(function(e) {157 e.preventDefault();158 $('#load-result').load('/save-state');159 });160 $('#load-state-link').click(function(e) {161 e.preventDefault();162 $('#load-result').load('/load-state');163 });164 $('#reset-link').click(function(e) {165 e.preventDefault();166 $('#load-result').load('/reset');167 });168 $('code').click(function() {169 if ((match = $(this).text().match(/^\$(.*)$/)) != null) {170 $(this).attr('orig-value', $(this).text());171 $(this).text(parseInt(match[1], 16).toString(2).replace(/(....)/g, '$1 '));172 } else if ($(this).is('[orig-value]')) {173 $(this).text($(this).attr('orig-value'));174 }175 });176 </script>177 </body>178</html>179`...

Full Screen

Full Screen

validate_test.go

Source:validate_test.go Github

copy

Full Screen

1package validate2import (3 "io/ioutil"4 "path/filepath"5 "strings"6 "testing"7 "github.com/hashicorp/consul/sdk/testutil"8 "github.com/mitchellh/cli"9 require "github.com/stretchr/testify/require"10)11func TestValidateCommand_noTabs(t *testing.T) {12 t.Parallel()13 if strings.ContainsRune(New(nil).Help(), '\t') {14 t.Fatal("help has tabs")15 }16}17func TestValidateCommand_FailOnEmptyFile(t *testing.T) {18 t.Parallel()19 tmpFile := testutil.TempFile(t, "consul")20 cmd := New(cli.NewMockUi())21 args := []string{tmpFile.Name()}22 code := cmd.Run(args)23 require.NotEqual(t, 0, code)24}25func TestValidateCommand_SucceedOnMinimalConfigFile(t *testing.T) {26 t.Parallel()27 td := testutil.TempDir(t, "consul")28 fp := filepath.Join(td, "config.json")29 err := ioutil.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)30 require.Nilf(t, err, "err: %s", err)31 cmd := New(cli.NewMockUi())32 args := []string{fp}33 code := cmd.Run(args)34 require.Equal(t, 0, code)35}36func TestValidateCommand_SucceedWithMinimalJSONConfigFormat(t *testing.T) {37 t.Parallel()38 td := testutil.TempDir(t, "consul")39 fp := filepath.Join(td, "json.conf")40 err := ioutil.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)41 require.Nilf(t, err, "err: %s", err)42 cmd := New(cli.NewMockUi())43 args := []string{"--config-format", "json", fp}44 code := cmd.Run(args)45 require.Equal(t, 0, code)46}47func TestValidateCommand_SucceedWithMinimalHCLConfigFormat(t *testing.T) {48 t.Parallel()49 td := testutil.TempDir(t, "consul")50 fp := filepath.Join(td, "hcl.conf")51 err := ioutil.WriteFile(fp, []byte("bind_addr = \"10.0.0.1\"\ndata_dir = \""+td+"\""), 0644)52 require.Nilf(t, err, "err: %s", err)53 cmd := New(cli.NewMockUi())54 args := []string{"--config-format", "hcl", fp}55 code := cmd.Run(args)56 require.Equal(t, 0, code)57}58func TestValidateCommand_SucceedWithJSONAsHCL(t *testing.T) {59 t.Parallel()60 td := testutil.TempDir(t, "consul")61 fp := filepath.Join(td, "json.conf")62 err := ioutil.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)63 require.Nilf(t, err, "err: %s", err)64 cmd := New(cli.NewMockUi())65 args := []string{"--config-format", "hcl", fp}66 code := cmd.Run(args)67 require.Equal(t, 0, code)68}69func TestValidateCommand_SucceedOnMinimalConfigDir(t *testing.T) {70 t.Parallel()71 td := testutil.TempDir(t, "consul")72 err := ioutil.WriteFile(filepath.Join(td, "config.json"), []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)73 require.Nilf(t, err, "err: %s", err)74 cmd := New(cli.NewMockUi())75 args := []string{td}76 code := cmd.Run(args)77 require.Equal(t, 0, code)78}79func TestValidateCommand_FailForInvalidJSONConfigFormat(t *testing.T) {80 t.Parallel()81 td := testutil.TempDir(t, "consul")82 fp := filepath.Join(td, "hcl.conf")83 err := ioutil.WriteFile(fp, []byte(`bind_addr = "10.0.0.1"\ndata_dir = "`+td+`"`), 0644)84 require.Nilf(t, err, "err: %s", err)85 cmd := New(cli.NewMockUi())86 args := []string{"--config-format", "json", fp}87 code := cmd.Run(args)88 require.NotEqual(t, 0, code)89}90func TestValidateCommand_Quiet(t *testing.T) {91 t.Parallel()92 td := testutil.TempDir(t, "consul")93 fp := filepath.Join(td, "config.json")94 err := ioutil.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)95 require.Nilf(t, err, "err: %s", err)96 ui := cli.NewMockUi()97 cmd := New(ui)98 args := []string{"-quiet", td}99 code := cmd.Run(args)100 require.Equalf(t, 0, code, "return code - expected: 0, bad: %d, %s", code, ui.ErrorWriter.String())101 require.Equal(t, "", ui.OutputWriter.String())102}...

Full Screen

Full Screen

Code

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 xlFile, _ := xlsx.OpenFile("1.xlsx")4 for _, sheet := range xlFile.Sheets {5 for _, row := range sheet.Rows {6 for _, cell := range row.Cells {7 text := cell.String()8 fmt.Printf("%s9 }10 }11 }12}

Full Screen

Full Screen

Code

Using AI Code Generation

copy

Full Screen

1import "fmt"2type td struct {3}4func (t td) Code() string {5}6func main() {7t := td{1}8fmt.Println(t.Code())9}

Full Screen

Full Screen

Code

Using AI Code Generation

copy

Full Screen

1func main() {2 fmt.Println(td.Code)3}4func main() {5 fmt.Println(td.Code())6}7func main() {8 fmt.Println(td.Code())9}10func main() {11 fmt.Println(td.Code)12}13func main() {14 fmt.Println(td.Code)15}16func main() {17 fmt.Println(td.Code())18}19func main() {20 fmt.Println(td.Code())21}

Full Screen

Full Screen

Code

Using AI Code Generation

copy

Full Screen

1import (2type td struct {3}4func (t td) Code() {5 fmt.Println("code method")6}7func main() {8 t := td{1, "one"}9 v := reflect.ValueOf(t)10 m := v.MethodByName("Code")11 m.Call(nil)12}13import (14type td struct {15}16func (t td) Code() {17 fmt.Println("code method")18}19func main() {20 t := td{1, "one"}21 v := reflect.ValueOf(t)22 m := v.MethodByName("Code")23 m.Call(nil)24}25import (26type td struct {27}28func (t td) Code() {29 fmt.Println("code method")30}31func main() {32 t := td{1, "one"}33 v := reflect.ValueOf(t)34 m := v.MethodByName("Code")35 m.Call(nil)36}37import (38type td struct {39}40func (t td) Code() {41 fmt.Println("code method")42}43func main() {44 t := td{1, "one"}45 v := reflect.ValueOf(t)46 m := v.MethodByName("Code")47 m.Call(nil)48}49import (50type td struct {51}52func (t td) Code() {53 fmt.Println("code method")54}55func main() {56 t := td{1, "one"}57 v := reflect.ValueOf(t)58 m := v.MethodByName("Code")59 m.Call(nil)60}61import (62type td struct {

Full Screen

Full Screen

Code

Using AI Code Generation

copy

Full Screen

1import (2type td struct {3}4func (t td) Code() {5 fmt.Println("Code method is called")6}7func main() {8 fmt.Println(reflect.TypeOf(a).Method(0).Name)9}10import (11type td struct {12}13func (t td) Code() {14 fmt.Println("Code method is called")15}16func main() {17 fmt.Println(reflect.TypeOf(a).Method(0).Func)18}19import (20type td struct {21}22func (t td) Code() {23 fmt.Println("Code method is called")24}25func main() {26 fmt.Println(reflect.TypeOf(a).Method(0).Func.Call(nil))27}28import (29type td struct {30}31func (t td) Code() {32 fmt.Println("Code method is called")33}34func main() {35 fmt.Println(reflect.TypeOf(a).Method(0).Func.Call(nil))36}37import (38type td struct {39}40func (t td) Code() {41 fmt.Println("Code method is called")42}43func main() {44 fmt.Println(reflect.TypeOf(a).Method(0).Func.Call([]reflect.Value{}))45}46import (47type td struct {48}49func (t td) Code() {50 fmt.Println("Code method is called")51}52func main() {53 fmt.Println(reflect.TypeOf(a).Method(0).Func.Call([]reflect.Value{reflect.ValueOf(a)}))54}55import (56type td struct {

Full Screen

Full Screen

Code

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 td := &td{code: "code"}4 fmt.Println(td.Code())5}6import (7func main() {8 td := &td{code: "code"}9 fmt.Println(td.Code())10}11main.main()12import (13func main() {14 td := &td{code: "code"}15 fmt.Println(td.Code())16}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Go-testdeep automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful